<%doc> <& select.html, # required field => 'myfield', # NAME property curr_value => 'foo', labels => { # or 'option_labels' # note: these will be escaped for you, don't escape them 'AL' => 'Alabama', 'AK' => 'Alaska', 'AR' => 'Arkansas', }, options => [ 'AL', 'AK', 'AR' ], curr_value => scalar( $cgi->param('myfield') ), # recommended id => 'myid', # DOM id # optional size => 1, # to show multiple rows at once style => '', # STYLE property multiple => 0, disabled => 0, onchange => 'do_something()', js_only => 0, # disables the whole thing element_etc => '', # anything else to put in the <% $size %> <% $style %> <% $opt{disabled} %> <% $onchange %> <% $opt{'element_etc'} %> > % if ( $opt{options} ) { % % foreach my $option ( @{ $opt{options} } ) { #just arrayref for now % } % % } 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) { % } % % } % } <%init> my %opt = @_; 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). '"' : ''; my $size = $opt{'size'} ? 'SIZE='.$opt{'size'} : ''; my $multiple = $opt{'multiple'} ? 'MULTIPLE' : '';