Example:
- include( '/elements/select-county.html',
+ <& /elements/select-county.html,
#recommended
country => $current_country,
state => $current_state,
prefix => $optional_unique_prefix,
onchange => $javascript,
disabled => 0, #bool
- disable_empty => 1, #defaults to 1, disable the empty option
+ disable_empty => 1, #defaults to 1, set to 0 to disable the empty option
empty_label => 'all', #label for empty option
- );
+ style => [ 'attribute:value', 'another:value' ],
+ &>
</%doc>
% if ( $countyflag ) {
function <% $pre %>state_changed(what, callback) {
+ what.form.<% $pre %>county.disabled = 'disabled';
+
state = what.options[what.selectedIndex].value;
country = what.form.<% $pre %>country.options[what.form.<% $pre %>country.selectedIndex].value;
// blank the current county list
for ( var i = what.form.<% $pre %>county.length; i >= 0; i-- )
what.form.<% $pre %>county.options[i] = null;
+
+% unless ( $opt{disable_empty} ) {
+ opt( what.form.<% $pre %>county, '', <% $opt{empty_label} |js_string %> );
+% }
// add the new counties
var countiesArray = eval('(' + counties + ')' );
if ( countiesArray.length > 1 ) {
what.form.<% $pre %>county.style.display = '';
- countyFormLabel.style.visibility = 'visible';
+ if ( countyFormLabel ) {
+ //countyFormLabel.style.visibility = 'visible';
+ countyFormLabel.style.display = '';
+ }
} else {
what.form.<% $pre %>county.style.display = 'none';
- countyFormLabel.style.visibility = 'hidden';
+ if ( countyFormLabel ) {
+ //countyFormLabel.style.visibility = 'hidden';
+ countyFormLabel.style.display = 'none';
+ }
}
+ what.form.<% $pre %>county.disabled = '';
+
//run the callback
- if ( callback != null )
+ if ( callback != null ) {
callback();
+ } else {
+ <% $pre %>county_changed(what.form.<% $pre %>county);
+ }
}
// go get the new counties
<SELECT NAME = "<% $pre %>county"
ID = "<% $pre %>county"
- onChange= "<% $opt{'onchange'} %>"
+ onChange= "<% $onchange %>"
<% $opt{'disabled'} %>
+ <% $style %>
>
% unless ( $opt{'disable_empty'} ) {
my $pre = $opt{'prefix'};
+
+# disable_cityupdate?
+my $onchange =
+ ( $opt{'disable_cityupdate'} ? '' : $pre.'county_changed(this); ' ).
+ $opt{'onchange'};
+
+my $county_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
+
my @counties = ();
if ( $countyflag ) {
@counties = map { length($_) ? $_ : $opt{'empty_data_value'} }
counties( $opt{'state'}, $opt{'country'} );
- # this is very hacky
- unless ( scalar(@counties) > 1 ) {
- if ( $opt{'disabled'} =~ /STYLE=/i ) {
- $opt{'disabled'} =~ s/STYLE="([^"]+)"/STYLE="$1; display:none"/i;
- } else {
- $opt{'disabled'} .= ' STYLE="display:none"';
- }
- }
+ push @$county_style, 'display:none'
+ unless scalar(@counties) > 1;
}
+my $style =
+ scalar(@$county_style)
+ ? 'STYLE="'. join(';', @$county_style). '"'
+ : '';
+
</%init>
<%once>