blob: 10cc8b995073f8a13fde7bfeb054e541fee18eaa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<%
##required
# 'table' => 'table_name',
# 'name_col' => 'name_column',
#
##strongly recommended (you want your forms to be "sticky" on errors, right?)
# 'value' => 'current_value',
#
##opt
# 'empty_label' => '', #better specify it though, the default might change
# 'hashref' => {},
# 'records' => \@records, #instead of hashref
my( %opt ) = @_;
my $key = dbdef->table($opt{'table'})->primary_key; #? $opt{'primary_key'} ||
my $name_col = $opt{'name_col'};
my @records = ();
if ( $opt{'records'} ) {
@records = @{ $opt{'records'} };
} else {
@records = qsearch( $opt{'table'}, ( $opt{'hashref'} || {} ) );
}
%>
<SELECT NAME="<%= $key %>">
<OPTION VALUE=""><%= $opt{'empty_label'} || 'all' %></OPTION>
<% foreach my $record ( sort { $a->$name_col() cmp $b->$name_col() }
@records
)
{
%>
<OPTION VALUE="<%= $record->$key() %>"<%= $opt{'value'} == $record->$key() ? ' SELECTED' : '' %>><%= $record->$name_col() %>
<% } %>
</SELECT>
|