diff options
Diffstat (limited to 'httemplate/elements/select-table.html')
-rw-r--r-- | httemplate/elements/select-table.html | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/httemplate/elements/select-table.html b/httemplate/elements/select-table.html index 4efbcbaf3..10a8b2741 100644 --- a/httemplate/elements/select-table.html +++ b/httemplate/elements/select-table.html @@ -34,6 +34,7 @@ Example: 'empty_label' => '', #better specify it though, the default might change 'multiple' => 0, # bool 'disable_empty' => 0, # bool (implied by multiple) + 'label_showkey' => 0, # bool 'label_callback' => sub { my $record = shift; return "label"; }, #more params controlling HTML stuff about the <SELECT> @@ -64,21 +65,32 @@ Example: > % while ( @pre_options ) { - <OPTION VALUE="<% shift(@pre_options) %>"><% shift(@pre_options) %> - +% my $pre_opt = shift(@pre_options); +% my $pre_label = shift(@pre_options); +% my $selected = ( ref($value) && $value->{$pre_opt} ) +% || ( $value eq $pre_opt ); + <OPTION VALUE="<% $pre_opt %>" + <% $selected ? 'SELECTED' : '' %> + ><% $pre_label %> % } % unless ( $opt{'multiple'} || $opt{'disable_empty'} ) { <OPTION VALUE=""><% $opt{'empty_label'} || 'all' %> % } -% foreach my $record ( sort { $a->$name_col() cmp $b->$name_col() } @records ) { +% foreach my $record ( sort { $a->$name_col() cmp $b->$name_col() +% || $a->$key() <=> $b->$key() +% } +% @records +% ) +% { % my $recvalue = $record->$key(); <OPTION VALUE="<% $recvalue %>" <% ref($value) && $value->{$recvalue} || $value == $recvalue ? ' SELECTED' : '' %> - ><% $opt{'label_callback'} + ><% $opt{'label_showkey'} ? "$recvalue: " : '' %> + <% $opt{'label_callback'} ? &{ $opt{'label_callback'} }( $record ) : $record->$name_col() %> @@ -139,7 +151,7 @@ if ( $opt{'records'} ) { }); } -unless ( ! $value +unless ( $value < 1 # !$value #ignore negatives too or ref($value) or ! exists( $opt{hashref}->{disabled} ) #?? or grep { $value == $_->$key() } @records |