fix browse results for selecting counties (resulting from separating tax classes...
[freeside.git] / httemplate / elements / select-state.html
1 <%doc>
2
3 Example:
4
5   include( '/elements/select-state.html',
6     #recommended
7     country    => $current_country,
8     state      => $current_state,
9
10     #optional
11     prefix        => $optional_unique_prefix,
12     onchange      => $javascript,
13     disabled      => 0, #bool
14     disable_empty => 1, #defaults to 1, disable the empty option
15     empty_label   => 'all', #label for empty option
16     disable_countyupdate => 0, #bool - disabled update of the select-state.html
17   );
18
19 </%doc>
20
21 <SELECT NAME     = "<% $pre %>state"
22         ID       = "<% $pre %>state"
23         onChange = "<% $onchange %>"
24 >
25
26 % unless ( $opt{'disable_empty'} ) {
27   <OPTION VALUE=""<% $opt{state} eq '' ? ' SELECTED' : '' %>><% $opt{empty_label} %>
28 % }
29
30 % foreach my $state ( keys %states ) { 
31
32   <OPTION VALUE="<% $state |h %>"<% $state eq $opt{'state'} ? ' SELECTED' : '' %>><% $states{$state} || '(n/a)' %>
33
34 % } 
35
36
37 </SELECT>
38
39 <%init>
40
41 my %opt = @_;
42 foreach my $opt (qw( state country prefix onchange disabled empty_label )) {
43   $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
44 }
45
46 $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
47
48 my $pre = $opt{'prefix'};
49
50 my $onchange =
51   ( $opt{'disable_countyupdate'} ? '' : $pre.'state_changed(this); ' ).
52   $opt{'onchange'};
53
54 tie my %states, 'Tie::IxHash', states_hash( $opt{'country'} ); 
55
56 </%init>
57