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