5 include( '/elements/select-table.html',
8 'table' => 'table_name',
9 'name_col' => 'name_column',
11 #strongly recommended (you want your forms to be "sticky" on errors, right?)
12 'value' => 'current_value',
15 'empty_label' => '', #better specify it though, the default might change
18 'records' => \@records, #instead of hashref
19 'pre_options' => [ 'value' => 'option' ], #before normal options
20 'element_name ' => '', #HTML element name, defaults to the name of
21 # the primary key column
22 'field' => '', #synonym for element_name
23 'element_etc' => '', #additional attributes (i.e. "DISABLED") for the
25 'multiple' => 0, # bool
26 'disable_empty' => 0, # bool (implied by multiple)
27 'debug' => 0, #set true to enable
33 <SELECT <% $opt{'multiple'} ? 'MULTIPLE' : '' %> NAME="<% $opt{'element_name'} || $opt{'field'} || $key %>" <% $opt{'element_etc'} %>>
35 % while ( @pre_options ) {
36 <OPTION VALUE="<% shift(@pre_options) %>"><% shift(@pre_options) %>
40 % unless ( $opt{'multiple'} || $opt{'disable_empty'} ) {
41 <OPTION VALUE=""><% $opt{'empty_label'} || 'all' %>
44 % foreach my $record ( sort { $a->$name_col() cmp $b->$name_col() } @records ) {
45 % my $recvalue = $record->$key();
46 <OPTION VALUE="<% $recvalue %>"
47 <% ref($value) && $value->{$recvalue} || $value == $recvalue
50 ><% $record->$name_col() %>
59 warn "elements/select-table.html: \n". Dumper(%opt)
60 if exists $opt{debug} && $opt{debug};
62 my $key = dbdef->table($opt{'table'})->primary_key; #? $opt{'primary_key'} ||
64 my $name_col = $opt{'name_col'};
66 my $value = $opt{'curr_value'} || $opt{'value'};
67 $value = [ split(/\s*,\s*/, $value) ] if $opt{'multiple'} && $value =~ /,/;
70 if ( $opt{'records'} ) {
71 @records = @{ $opt{'records'} };
74 'table' => $opt{'table'},
75 'hashref' => ( $opt{'hashref'} || {} ),
76 'extra_sql' => ( $opt{'extra_sql'} || '' ),
82 or ! exists( $opt{hashref}->{disabled} ) #??
83 or grep { $value == $_->$key() } @records
85 delete $opt{hashref}->{disabled};
86 $opt{hashref}->{$key} = $value;
87 my $record = qsearchs( {
88 'table' => $opt{table},
89 'hashref' => $opt{hashref},
90 'extra_sql' => ( $opt{extra_sql} || '' ),
92 push @records, $record if $record;
95 if ( ref( $value ) eq 'ARRAY' ) {
96 $value = { map { $_ => 1 } @$value };
99 my @pre_options = $opt{pre_options} ? @{ $opt{pre_options} } : ();