RT# 82949 - changes section name from fees to pricing, better opiton
[freeside.git] / httemplate / elements / select-tiered.html
index 99b2852..e76bf76 100644 (file)
@@ -59,7 +59,11 @@ main argument list, and will be applied to the last tier.
   >
 %   if ( $i == 0 ) {
 %     my $options = $tiers_by_key->[0]->{''};
-%     foreach ( sort keys %$options ) {
+%     #foreach ( sort keys %$options ) {
+%     foreach ( sort { lc($options->{$a}) cmp lc($options->{$b}) }
+%                 keys %$options
+%             )
+%     {
   <OPTION VALUE="<%$_ |h%>" <% $curr_values->[$i] eq $_ ? 'SELECTED' : ''%>>
   <% $options->{$_} |h%></OPTION>
 %     }
@@ -68,8 +72,8 @@ main argument list, and will be applied to the last tier.
 </SELECT>
 <% $tier->{after} %>
 % } #foreach $tier
+
 <SCRIPT type="text/javascript">
-% my $json = JSON->new->canonical; #sort
 var <% $pre %>tiers = <% $json->encode($tiers_by_key) %>;
 var <% $pre %>curr_values = <% $json->encode($curr_values) %>;
 function <% $pre %>select_change(select_this, i) {
@@ -120,6 +124,9 @@ my %opt = @_;
 my $pre = $opt{prefix} || '';
 my $tiers = $opt{tiers} or die "no tiers defined";
 
+my $json = Cpanel::JSON::XS->new();
+$json->canonical;
+
 my $i;
 for( $i = 0; $i < @$tiers; $i++ ) {
   my $tier = $tiers->[$i];
@@ -167,6 +174,8 @@ for( $i = 0; $i < @$tiers; $i++ ) {
         $children_of{$key}->{''} = $tier->{empty_label};
       }
     }
+    # ensure that there's always at least one empty label
+    $children_of{''}->{''} = $tier->{empty_label};
   }
   $tier->{by_key} = \%children_of;
 }