diff options
author | ivan <ivan> | 2006-12-27 01:07:28 +0000 |
---|---|---|
committer | ivan <ivan> | 2006-12-27 01:07:28 +0000 |
commit | 8e95986bf97e83e00b0375dd1517c4bd0afb23e5 (patch) | |
tree | bf313afe11c3b188acbc02bd647f5535a851c347 /httemplate/edit/cust_main | |
parent | 84191efb2ad13dd839372df7a948dc08a6bb5ff5 (diff) |
fix county selector
Diffstat (limited to 'httemplate/edit/cust_main')
-rw-r--r-- | httemplate/edit/cust_main/select-county.html | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/httemplate/edit/cust_main/select-county.html b/httemplate/edit/cust_main/select-county.html index c9b64bf4f..5b068214e 100644 --- a/httemplate/edit/cust_main/select-county.html +++ b/httemplate/edit/cust_main/select-county.html @@ -16,8 +16,8 @@ function <% $opt{'prefix'} %>state_changed(what, callback) { - state = what.options[what.selectedIndex].text; - country = what.form.<% $opt{'prefix'} %>country.options[what.form.<% $opt{'prefix'} %>country.selectedIndex].text; + state = what.options[what.selectedIndex].value; + country = what.form.<% $opt{'prefix'} %>country.options[what.form.<% $opt{'prefix'} %>country.selectedIndex].value; function <% $opt{'prefix'} %>update_counties(counties) { @@ -34,6 +34,12 @@ opt(what.form.<% $opt{'prefix'} %>county, countiesArray[s], countyLabel); } + if ( countiesArray.length > 1 ) { + what.form.<% $opt{'prefix'} %>county.style.display = ''; + } else { + what.form.<% $opt{'prefix'} %>county.style.display = 'none'; + } + //run the callback if ( callback != null ) callback(); @@ -47,14 +53,8 @@ </SCRIPT> <SELECT NAME="<% $opt{'prefix'} %>county" onChange="<% $opt{'onchange'} %>" <% $opt{'disabled'} %>> -% foreach my $county ( -% sort -% map { $_->county } -% qsearch('cust_main_county', { 'state' => $opt{'state'}, -% 'country' => $opt{'country'}, -% } -% ) -% ) { + +% foreach my $county ( @counties ) { <OPTION VALUE="<% $county %>"<% $county eq $opt{'county'} ? ' SELECTED' : '' %>><% $county %> @@ -75,14 +75,44 @@ % } <%init> + my %opt = @_; foreach my $opt (qw( county state country prefix onchange disabled )) { $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_}); } +my @counties = (); +if ( $countyflag ) { + + @counties = + sort + map { $_->county } + qsearch( { + 'select' => 'DISTINCT county', + 'table' => 'cust_main_county', + 'hashref' => { 'state' => $opt{'state'}, + 'country' => $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"'; + } + } + +} + +</%init> +<%once> + my $sql = "SELECT COUNT(*) FROM cust_main_county". " WHERE county IS NOT NULL AND county != ''"; my $sth = dbh->prepare($sql) or die dbh->errstr; $sth->execute or die $sth->errstr; my $countyflag = $sth->fetchrow_arrayref->[0]; -</%init> + +</%once> |