1 %# BEGIN BPS TAGGED BLOCK {{{
5 %# This software is Copyright (c) 1996-2009 Best Practical Solutions, LLC
6 %# <jesse@bestpractical.com>
8 %# (Except where explicitly superseded by other copyright notices)
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 %# General Public License for more details.
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
30 %# CONTRIBUTION SUBMISSION POLICY:
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
47 %# END BPS TAGGED BLOCK }}}
49 see docs/using_forms_widgets.pod
51 <div id="form-box-<% lc $Name %>" class="widget">
52 % if ( $Description ) {
53 <span class="label"><% $Description %></span>
55 <span class="value"><& SELF:InputOnly, %ARGS &></span>
59 $Description => undef,
65 $Description => undef,
68 $ValuesCallback => undef,
74 $DefaultLabel => undef,
77 $AlternativeLabel => loc('other...'),
81 <select name="<% $Name %>">
85 % $selected = 'selected="selected"' unless @CurrentValue;
86 <option value="__empty_value__" <% $selected |n %>><% $DefaultLabel %></option>
89 % foreach my $v( @Values ) {
91 % $selected = 'selected="selected"' if delete $CurrentValue{ $v };
92 <option value="<% $v %>" <% $selected |n %>><% loc($ValuesLabel{ $v } || $v) %></option>
95 % if ( $Alternative ) {
97 % $selected = 'selected="selected"' if keys %CurrentValue;
98 <option value="__alternative_value__" <% $selected |n %>><% $AlternativeLabel %></option>
102 % if ( $Alternative ) {
103 <input type="text" class="alternative" name="Alternative-<% $Name %>" value="<% join ', ', @CurrentValue %>" />
106 my %CurrentValue = map {$_ => 1} grep defined, @CurrentValue;
107 if ( $ValuesCallback ) {
108 my $values = $ValuesCallback->(
109 CurrentUser => $session{'CurrentUser'},
112 if ( ref $values eq 'ARRAY' ) {
115 %ValuesLabel = %$values;
116 @Values = keys %ValuesLabel;
119 unless (defined $DefaultLabel ) {
120 $DefaultLabel = loc('Use system default ([_1])',
121 join ', ', map loc($ValuesLabel{$_} || $_), grep defined,
144 my $value = $Arguments->{ $Name };
145 if( !defined $value || $value eq '__empty_value__' ) {
146 return undef if $Default;
147 return [ @DefaultValue ] if $Multiple;
148 return $DefaultValue[0];
150 $value = [$value] unless ref $value;
152 if ( $Alternative ) {
153 my $alt = $Arguments->{ "Alternative-". $Name };
155 push @$value, split /\s*,\s*/, $alt;
161 splice @$value, 1 unless $Multiple;
165 return $value->[0] unless $Multiple;