ticket 1443 add account type and bank state for echeck processing
[freeside.git] / httemplate / edit / cust_main / select-state.html
index 98e685a..4f1c056 100644 (file)
@@ -1,27 +1,24 @@
-<%
+<SELECT NAME="<% $opt{'prefix'} %>state" onChange="<% $opt{'prefix'} %>state_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
 
-  my %opt = @_;
-  foreach my $opt (qw( county state country prefix onchange disabled )) {
-    $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
-  }
+% if ($opt{empty}) {
+  <OPTION VALUE=""<% $opt{state} eq '' ? ' SELECTED' : '' %>><% $opt{empty} %>
+% }
 
-%>
+% foreach my $state ( keys %states ) { 
 
-<SELECT NAME="<%= $opt{'prefix'} %>state" onChange="<%= $opt{'prefix'} %>state_changed(this); <%= $opt{'onchange'} %>" <%= $opt{'disabled'} %>>
+  <OPTION VALUE="<% $state %>"<% $state eq $opt{'state'} ? ' SELECTED' : '' %>><% $states{$state} || '(n/a)' %>
 
-<% foreach my $state (
-     sort
-     map { $_->state }
-     qsearch( 'cust_main_county',
-              { 'country' => $opt{'country'} },
-              'DISTINCT ON ( state ) *',
-            )
-   ) {
-%>
+% } 
 
-  <OPTION VALUE="<%= $state %>"<%= $state eq $opt{'state'} ? ' SELECTED' : '' %>><%= $state || '(n/a)' %>
-
-<% } %>
 
 </SELECT>
 
+<%init>
+my %opt = @_;
+foreach my $opt (qw( county state country prefix onchange disabled empty )) {
+  $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
+}
+
+tie my %states, 'Tie::IxHash', states_hash( $opt{'country'} ); 
+</%init>
+