<%doc> Example: <& /elements/city.html, #recommended country => $current_country, state => $current_state, county => $current_county, city => $current_city, #optional prefix => $optional_unique_prefix, onchange => $javascript, disabled => 0, #bool style => [ 'attribute:value', 'another:value' ], disable_empty => 1, #defaults to 1, set to 0 to disable the empty option empty_label => 'all', #label for empty option disable_text => 1, # disable the text input (just show the select) #doesn't work as an option yet, set when conf tax_district_method #disable_select => 1, # disable the selector (just show a text input) &> % if ( $disable_select ) { % } % else { <% include('/elements/xmlhttp.html', 'url' => $p.'misc/cities.cgi', 'subs' => [ $pre. 'get_cities' ], ) %> % } #!disable_select <% $text_style %> % } > % if ( $disable_select ) { %# avoid JS errors % } else { % } <%init> my %opt = @_; my $pre = $opt{'prefix'}; my $conf = new FS::Conf; # Using tax_district_method implies that there's not a preloaded city/county # tax district table. my $disable_select = 1 if $conf->config('tax_district_method'); $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'}); if ($conf->exists('cust_main-no_city_in_address')) { $opt{'disable_text'} = 1; $disable_select = 1; } my $text_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : []; my $select_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : []; push @$text_style, @{ $opt{'text_style'} } if $opt{'text_style'}; push @$select_style, @{ $opt{'select_style'} } if $opt{'select_style'}; my @cities = cities( $opt{'county'}, $opt{'state'}, $opt{'country'} ); my $saved_city = ''; if ( scalar(@cities) > 1 || $cities[0] and !$disable_select ) { push @$text_style, 'display:none'; } else { push @$select_style, 'display:none'; $saved_city = $opt{'city'}; } $text_style = scalar(@$text_style) ? 'STYLE="'. join(';', @$text_style). '"' : ''; $select_style = scalar(@$select_style) ? 'STYLE="'. join(';', @$select_style). '"' : '';