This commit was manufactured by cvs2svn to create tag 'freeside_2_1_1'.
[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     style         => [ 'attribute:value', 'another:value' ],
18   );
19
20 </%doc>
21
22 <SELECT NAME     = "<% $pre %>state"
23         ID       = "<% $pre %>state"
24         onChange = "<% $onchange %>"
25         <% $opt{'disabled'} %>
26         <% $style %>
27 >
28
29 % unless ( $opt{'disable_empty'} ) {
30   <OPTION VALUE=""<% $opt{state} eq '' ? ' SELECTED' : '' %>><% $opt{empty_label} %>
31 % }
32
33 % foreach my $state ( keys %states ) { 
34
35   <OPTION VALUE="<% $state |h %>"<% $state eq $opt{'state'} ? ' SELECTED' : '' %>><% $states{$state} || '(n/a)' %>
36
37 % } 
38
39
40 </SELECT>
41
42 <%init>
43
44 my %opt = @_;
45 foreach my $opt (qw( state country prefix onchange disabled empty_label )) {
46   $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
47 }
48
49 $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
50
51 my $pre = $opt{'prefix'};
52
53 my $onchange =
54   ( $opt{'disable_countyupdate'} ? '' : $pre.'state_changed(this); ' ).
55   $opt{'onchange'};
56
57 $opt{'style'} ||= [];
58 my $style =
59   scalar(@{$opt{style}})
60     ? 'STYLE="'. join(';', @{$opt{style}}). '"'
61     : '';
62
63 tie my %states, 'Tie::IxHash', states_hash( $opt{'country'} ); 
64
65 </%init>
66