5249a6dc3e43d33d7521af7d0e3f4f63a12a2106
[freeside.git] / httemplate / elements / select.html
1 % unless ( $opt{'js_only'} ) {
2
3 <SELECT NAME          = "<% $opt{field} %>"
4         ID            = "<% $opt{id} %>"
5         previousValue = "<% $curr_value %>"
6         previousText  = "<% $labels->{$curr_value} || $curr_value %>"
7         <% $style %>
8         <% $opt{disabled} %>
9         <% $onchange %>
10 >
11
12 % if ( $opt{options} ) {
13 %
14 %   foreach my $option ( @{ $opt{options} } ) { #just arrayref for now
15
16       <OPTION VALUE="<% $option %>"
17               <% $opt{curr_value} eq $option ? 'SELECTED' : '' %>
18       >
19         <% $labels->{$option} || $option %>
20       </OPTION>
21
22 %   }
23 %
24 % } else { #deprecated weird value hashref used only by reason.html
25 %
26 %   my $aref = $opt{'value'}->{'values'};
27 %   my $vkey = $opt{'value'}->{'vcolumn'};
28 %   my $ckey = $opt{'value'}->{'ccolumn'};
29 %   foreach my $v (@$aref) {
30
31       <OPTION VALUE="<% $v->$vkey %>"
32               <% ($opt{curr_value} eq $v->$vkey) ? 'SELECTED' : '' %>
33       >
34         <% $v->$ckey %>
35       </OPTION>
36
37 %   }
38 %
39 % }
40
41 </SELECT>
42
43 % }
44 <%init>
45
46 my %opt = @_;
47
48 my $onchange = $opt{'onchange'}
49                  ? 'onChange="'. $opt{'onchange'}. '(this)"'
50                  : '';
51
52 my $labels = $opt{'option_labels'} || $opt{'labels'};
53
54 my $curr_value = $opt{'curr_value'};
55
56 my $onchange = '';
57 if ( $opt{'onchange'} ) {
58   $onchange = $opt{'onchange'};
59   $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
60   $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
61                                         #callbacks should act the same
62   $onchange = 'onChange="'. $onchange. '"' unless $onchange =~ /^onChange=/i;
63 }
64
65 $opt{'disabled'} = &{ $opt{'disabled'} }( \%opt )
66   if ref($opt{'disabled'}) eq 'CODE';
67 $opt{'disabled'} = 'DISABLED'
68   if $opt{'disabled'} && $opt{'disabled'} !~ /disabled/i; # uuh... yeah?
69
70 my @style = ref($opt{'style'})
71               ? @{ $opt{'style'} }
72               : $opt{'style'}
73                 ? ( $opt{'style'} )
74                 : ();
75
76 my $style = scalar(@style) ? 'STYLE="'. join(';', @style). '"' : '';
77
78
79 </%init>