<%doc> Example: <& /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' ], state_disable_empty => 1, #defaults to 1, disable the state empty option state_empty_label => 'all', #label for state empty option &> % #maybe this makes more sense in select-state.html? % # (county update is in select-county... and we wouldn't have to pass "state_" % # options) % 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 FS::geocode_Mixin->code2country($a) cmp FS::geocode_Mixin->code2country($b) } map { $_->country } qsearch({ 'select' => 'country', 'table' => 'cust_main_county', 'hashref' => {}, 'extra_sql' => 'GROUP BY country', }) );