summaryrefslogtreecommitdiff
path: root/httemplate/elements/select.html
diff options
context:
space:
mode:
Diffstat (limited to 'httemplate/elements/select.html')
-rw-r--r--httemplate/elements/select.html79
1 files changed, 79 insertions, 0 deletions
diff --git a/httemplate/elements/select.html b/httemplate/elements/select.html
new file mode 100644
index 0000000..5249a6d
--- /dev/null
+++ b/httemplate/elements/select.html
@@ -0,0 +1,79 @@
+% unless ( $opt{'js_only'} ) {
+
+<SELECT NAME = "<% $opt{field} %>"
+ ID = "<% $opt{id} %>"
+ previousValue = "<% $curr_value %>"
+ previousText = "<% $labels->{$curr_value} || $curr_value %>"
+ <% $style %>
+ <% $opt{disabled} %>
+ <% $onchange %>
+>
+
+% if ( $opt{options} ) {
+%
+% foreach my $option ( @{ $opt{options} } ) { #just arrayref for now
+
+ <OPTION VALUE="<% $option %>"
+ <% $opt{curr_value} eq $option ? 'SELECTED' : '' %>
+ >
+ <% $labels->{$option} || $option %>
+ </OPTION>
+
+% }
+%
+% } else { #deprecated weird value hashref used only by reason.html
+%
+% my $aref = $opt{'value'}->{'values'};
+% my $vkey = $opt{'value'}->{'vcolumn'};
+% my $ckey = $opt{'value'}->{'ccolumn'};
+% foreach my $v (@$aref) {
+
+ <OPTION VALUE="<% $v->$vkey %>"
+ <% ($opt{curr_value} eq $v->$vkey) ? 'SELECTED' : '' %>
+ >
+ <% $v->$ckey %>
+ </OPTION>
+
+% }
+%
+% }
+
+</SELECT>
+
+% }
+<%init>
+
+my %opt = @_;
+
+my $onchange = $opt{'onchange'}
+ ? 'onChange="'. $opt{'onchange'}. '(this)"'
+ : '';
+
+my $labels = $opt{'option_labels'} || $opt{'labels'};
+
+my $curr_value = $opt{'curr_value'};
+
+my $onchange = '';
+if ( $opt{'onchange'} ) {
+ $onchange = $opt{'onchange'};
+ $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
+ $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack. all onchange
+ #callbacks should act the same
+ $onchange = 'onChange="'. $onchange. '"' unless $onchange =~ /^onChange=/i;
+}
+
+$opt{'disabled'} = &{ $opt{'disabled'} }( \%opt )
+ if ref($opt{'disabled'}) eq 'CODE';
+$opt{'disabled'} = 'DISABLED'
+ if $opt{'disabled'} && $opt{'disabled'} !~ /disabled/i; # uuh... yeah?
+
+my @style = ref($opt{'style'})
+ ? @{ $opt{'style'} }
+ : $opt{'style'}
+ ? ( $opt{'style'} )
+ : ();
+
+my $style = scalar(@style) ? 'STYLE="'. join(';', @style). '"' : '';
+
+
+</%init>