%doc>
Example:
include( '/elements/select-country.html',
#recommended
country => $current_country,
#optional
prefix => $optional_unique_prefix,
onchange => $javascript,
disabled => 0, #bool
disable_empty => 1, #defaults to 1, disable the empty option
empty_label => 'all', #label for empty option
disable_stateupdate => 0, #bool - disabled update of the select-state.html
style => [ 'attribute:value', 'another:value' ],
);
%doc>
% unless ( $opt{'disable_stateupdate'} ) {
<% include('/elements/xmlhttp.html',
'url' => $p.'misc/states.cgi',
'subs' => [ $pre. 'get_states' ],
)
%>
% }
<%init>
my %opt = @_;
foreach my $opt (qw( country prefix onchange disabled disable_stateupdate )) {
$opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
}
$opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
my $pre = $opt{'prefix'};
my $onchange =
( $opt{'disable_stateupdate'} ? '' : $pre.'country_changed(this); ' ).
$opt{'onchange'};
$opt{'style'} ||= [];
my $style =
scalar(@{$opt{style}})
? 'STYLE="'. join(';', @{$opt{style}}). '"'
: '';
my $conf = new FS::Conf;
my $default = $conf->config('countrydefault') || 'US';
my @all_countries = (
sort { ($b eq $default) <=> ($a eq $default)
or code2country($a) cmp code2country($b)
}
map { $_->country }
qsearch({
'select' => 'country',
'table' => 'cust_main_county',
'hashref' => {},
'extra_sql' => 'GROUP BY country',
})
);
%init>