disabled => 0, #bool
# disable_empty => 1, #defaults to 1, disable the empty option
# empty_label => 'all', #label for empty option
+# disable_select => 1, # disable the selector (just show a text input)
style => [ 'attribute:value', 'another:value' ],
);
</%doc>
+% if ( $disable_select ) {
+<SCRIPT TYPE="text/javascript">
+function <% $pre %>county_changed(what, callback) {}
+</SCRIPT>
+% }
+% else {
+
+
<% include('/elements/xmlhttp.html',
'url' => $p.'misc/cities.cgi',
'subs' => [ $pre. 'get_cities' ],
what.options[length] = optionName;
}
- var saved_<%$pre%>city= '';
+ var saved_<%$pre%>city= '<% $saved_city |h %>';
function <% $pre %>county_changed(what, callback) {
if ( citiesArray.length > 1 || citiesArray[0].length ) {
// turn off the text city, turn on the select
saved_<%$pre%>city = what.form.<%$ pre %>city.value;
+ <%$pre%>city_select_changed(what.form.<% $pre %>city_select);
what.form.<% $pre %>city.style.display = 'none';
what.form.<% $pre %>city_select.style.display = '';
- } else {
+ } else if ( what.form.<% $pre %>city.style.display == 'none' ) {
// turn on the text city, turn off the select
what.form.<%$ pre %>city.value = saved_<%$pre%>city;
what.form.<% $pre %>city.style.display = '';
</SCRIPT>
+% } #!disable_select
+
<INPUT TYPE = "text"
NAME = "<%$pre%>city"
ID = "<%$pre%>city"
<% $text_style %>
>
+% if ( $disable_select ) {
+%# avoid JS errors
+<INPUT TYPE="hidden" ID="city_select">
+% }
+% else {
+
<SELECT NAME = "<%$pre%>city_select"
ID = "<%$pre%>city_select"
onChange = "<%$pre%>city_select_changed(this); <% $opt{'onchange'} %>"
% }
</SELECT>
-
+% }
%# VALUE = "<% $curr_value |h %>"
<%init>
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');
+
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'} );
-if ( scalar(@cities) > 1 || $cities[0] ) {
+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 =