4 # 'table' => 'table_name',
5 # 'name_col' => 'name_column',
7 ##strongly recommended (you want your forms to be "sticky" on errors, right?)
8 # 'value' => 'current_value',
11 # 'empty_label' => '', #better specify it though, the default might change
14 # 'records' => \@records, #instead of hashref
15 # 'pre_options' => [ 'value' => 'option' ], #before normal options
16 # 'element_name' => '', #HTML element name, defaults to the name of
17 # # the primary key column
18 # 'element_etc' => '', #additional attributes (i.e. "DISABLED") for the
23 #warn "***** select-table: \n". Dumper(%opt);
25 my $key = dbdef->table($opt{'table'})->primary_key; #? $opt{'primary_key'} ||
27 my $name_col = $opt{'name_col'};
30 if ( $opt{'records'} ) {
31 @records = @{ $opt{'records'} };
34 'table' => $opt{'table'},
35 'hashref' => ( $opt{'hashref'} || {} ),
36 'extra_sql' => ( $opt{'extra_sql'} || '' ),
40 my @pre_options = $opt{'pre_options'} ? @{ $opt{'pre_options'} } : ();
44 <SELECT NAME="<%= $opt{'element_name'} || $key %>" <%= $opt{'element_etc'} %>>
46 <% while ( @pre_options ) { %>
47 <OPTION VALUE="<%= shift(@pre_options) %>"><%= shift(@pre_options) %>
50 <OPTION VALUE=""><%= $opt{'empty_label'} || 'all' %>
52 <% foreach my $record ( sort { $a->$name_col() cmp $b->$name_col() }
58 <OPTION VALUE="<%= $record->$key() %>"<%= $opt{'value'} == $record->$key() ? ' SELECTED' : '' %>><%= $record->$name_col() %>