This commit was generated by cvs2svn to compensate for changes in r8690,
[freeside.git] / httemplate / elements / select-table.html
index e7baaf5..45585a8 100644 (file)
@@ -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
+            <% $opt{'all_selected'} || ref($value) && $value->{$recvalue} || $value == $recvalue
                ? ' SELECTED' : ''
             %>
-    ><% $opt{'label_callback'}
+    ><% $opt{'label_showkey'} ? "$recvalue: " : '' %>
+     <% $opt{'label_callback'}
           ? &{ $opt{'label_callback'} }( $record )
           : $record->$name_col()
      %>