5 <& /elements/select-country.html,
7 country => $current_country,
10 prefix => $optional_unique_prefix,
11 onchange => $javascript,
13 disable_empty => 1, #defaults to 1, disable the empty option
14 empty_label => 'all', #label for empty option
15 disable_stateupdate => 0, #bool - disabled update of the select-state.html
16 style => [ 'attribute:value', 'another:value' ],
18 state_disable_empty => 1, #defaults to 1, disable the state empty option
19 state_empty_label => 'all', #label for state empty option
23 % #maybe this makes more sense in select-state.html?
24 % # (county update is in select-county... and we wouldn't have to pass "state_"
26 % unless ( $opt{'disable_stateupdate'} ) {
28 <% include('/elements/xmlhttp.html',
29 'url' => $p.'misc/states.cgi',
30 'subs' => [ $pre. 'get_states' ],
34 <SCRIPT TYPE="text/javascript">
36 function opt(what,value,text) {
37 var optionName = new Option(text, value, false, false);
38 var length = what.length;
39 what.options[length] = optionName;
42 function <% $pre %>country_changed(what, callback) {
44 what.form.<% $pre %>state.disabled = 'disabled';
46 country = what.options[what.selectedIndex].value;
48 function <% $pre %>update_states(states) {
50 // blank the current state list
51 for ( var i = what.form.<% $pre %>state.length; i >= 0; i-- )
52 what.form.<% $pre %>state.options[i] = null;
55 var statesArray = eval('(' + states + ')' );
56 % unless ( $opt{'disable_empty'} ) {
57 statesArray.unshift('', '');
60 for ( var s = 0; s < statesArray.length; s=s+2 ) {
61 var stateLabel = statesArray[s+1];
62 if ( stateLabel == "" )
63 stateLabel = <% $opt{state_empty_label} || '(n/a)' |js_string %>;
64 opt(what.form.<% $pre %>state, statesArray[s], stateLabel);
67 what.form.<% $pre %>state.disabled = '';
70 if ( callback != null ) {
73 <% $pre %>state_changed(what.form.<% $pre %>state);
77 // go get the new states
78 <% $pre %>get_states( country, <% $pre %>update_states );
86 <SELECT NAME = "<% $pre %>country"
87 ID = "<% $pre %>country"
88 onChange = "<% $onchange %>"
89 <% $opt{'disabled'} %>
93 % unless ( $opt{'disable_empty'} ) {
94 <OPTION VALUE=""><% $opt{'empty_label'} || '(all)' %></OPTION>
97 % foreach my $country ( @all_countries ) {
98 <OPTION VALUE="<% $country |h %>"<% $country eq $opt{'country'} ? ' SELECTED' : '' %>>
99 <% FS::geocode_Mixin->code2country($country). " ($country)" |h %>
108 foreach my $opt (qw( country prefix onchange disabled disable_stateupdate )) {
109 $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
112 $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
114 my $pre = $opt{'prefix'};
117 ( $opt{'disable_stateupdate'} ? '' : $pre.'country_changed(this); ' ).
120 $opt{'style'} ||= [];
122 scalar(@{$opt{style}})
123 ? 'STYLE="'. join(';', @{$opt{style}}). '"'
126 my $conf = new FS::Conf;
127 my $default = $conf->config('countrydefault') || 'US';
129 my @all_countries = (
130 sort { ($b eq $default) <=> ($a eq $default)
131 or FS::geocode_Mixin->code2country($a) cmp FS::geocode_Mixin->code2country($b)
135 'select' => 'country',
136 'table' => 'cust_main_county',
138 'extra_sql' => 'GROUP BY country',