Skip to content

Commit

Permalink
Applied patch from Steve Taylor that allows checkbox_groups to be dis…
Browse files Browse the repository at this point in the history
…abled with a new -disabled=> option.
  • Loading branch information
lstein committed Feb 23, 2007
1 parent 280ffdc commit 11662e4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 23 deletions.
48 changes: 31 additions & 17 deletions CGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use Carp 'croak';
# The most recent version and complete docs are available at:
# http://stein.cshl.org/WWW/software/CGI/

$CGI::revision = '$Id: CGI.pm,v 1.226 2006-12-04 22:33:12 lstein Exp $';
$CGI::VERSION='3.26';
$CGI::revision = '$Id: CGI.pm,v 1.227 2007-02-23 23:03:16 lstein Exp $';
$CGI::VERSION='3.27';

# HARD-CODED LOCATION FOR FILE UPLOAD TEMPORARY FILES.
# UNCOMMENT THIS ONLY IF YOU KNOW WHAT YOU'RE DOING.
Expand Down Expand Up @@ -2334,15 +2334,14 @@ sub _box_group {
my($name,$values,$defaults,$linebreak,$labels,$attributes,
$rows,$columns,$rowheaders,$colheaders,
$override,$nolabels,$tabindex,@other) =
$override,$nolabels,$tabindex,$disabled,@other) =
rearrange([ NAME,[VALUES,VALUE],[DEFAULT,DEFAULTS],LINEBREAK,LABELS,ATTRIBUTES,
ROWS,[COLUMNS,COLS],ROWHEADERS,COLHEADERS,
[OVERRIDE,FORCE],NOLABELS,TABINDEX
ROWS,[COLUMNS,COLS],[ROWHEADERS,ROWHEADER],[COLHEADERS,COLHEADER],
[OVERRIDE,FORCE],NOLABELS,TABINDEX,DISABLED
],@_);
my($result,$checked);
my($result,$checked,@elements,@values);
my(@elements,@values);
@values = $self->_set_values_and_labels($values,\$labels,$name);
my %checked = $self->previous_or_default($name,$defaults,$override);
Expand All @@ -2362,10 +2361,21 @@ sub _box_group {
}
}
%tabs = map {$_=>$self->element_tab} @values unless %tabs;
my $other = @other ? "@other " : '';
my $radio_checked;
# for disabling groups of radio/checkbox buttons
my %disabled;
foreach (@{$disabled}) {
$disabled{$_}=1;
}
foreach (@values) {
my $disable="";
if ($disabled{$_}) {
$disable="disabled='1'";
}
my $checkit = $self->_checked($box_type eq 'radio' ? ($checked{$_} && !$radio_checked++)
: $checked{$_});
my($break);
Expand All @@ -2380,16 +2390,18 @@ sub _box_group {
$label = $_;
$label = $labels->{$_} if defined($labels) && defined($labels->{$_});
$label = $self->escapeHTML($label,1);
$label = "<span style=\"color:gray\">$label</span>" if $disabled{$_};
}
my $attribs = $self->_set_attributes($_, $attributes);
my $tab = $tabs{$_};
$_=$self->escapeHTML($_);
if ($XHTML) {
push @elements,
CGI::label(
qq(<input type="$box_type" name="$name" value="$_" $checkit$other$tab$attribs/>$label)).${break};
qq(<input type="$box_type" name="$name" value="$_" $checkit$other$tab$attribs$disable/>$label)).${break};
} else {
push(@elements,qq/<input type="$box_type" name="$name" value="$_"$checkit$other$tab$attribs>${label}${break}/);
push(@elements,qq/<input type="$box_type" name="$name" value="$_"$checkit$other$tab$attribs$disable>${label}${break}/);
}
}
$self->register_parameter($name);
Expand Down Expand Up @@ -6290,6 +6302,7 @@ selected items can be retrieved with:
-values=>['eenie','meenie','minie','moe'],
-default=>['eenie','moe'],
-linebreak=>'true',
-disabled => ['moe'],
-labels=>\%labels,
-attributes=>\%attributes);
Expand Down Expand Up @@ -6342,13 +6355,14 @@ printed next to them. If not provided, the values will be used as the
default.
Modern browsers can take advantage of the optional parameters
B<-rows>, and B<-columns>. These parameters cause checkbox_group() to
return an HTML3 compatible table containing the checkbox group
formatted with the specified number of rows and columns. You can
provide just the -columns parameter if you wish; checkbox_group will
calculate the correct number of rows for you.
The optional parameters B<-rows>, and B<-columns> cause
checkbox_group() to return an HTML3 compatible table containing the
checkbox group formatted with the specified number of rows and
columns. You can provide just the -columns parameter if you wish;
checkbox_group will calculate the correct number of rows for you.
The option b<-disabled> takes an array of checkbox values and disables
them by greying them out (this may not be supported by all browsers).
The optional B<-attributes> argument is provided to assign any of the
common HTML attributes to an individual menu item. It's a pointer to
Expand Down Expand Up @@ -6500,7 +6514,7 @@ the -columns parameter if you wish; radio_group will calculate the
correct number of rows for you.
To include row and column headings in the returned table, you
can use the B<-rowheader> and B<-colheader> parameters. Both
can use the B<-rowheaders> and B<-colheaders> parameters. Both
of these accept a pointer to an array of headings to use.
The headings are just decorative. They don't reorganize the
interpretation of the radio buttons -- they're still a single named
Expand Down
10 changes: 5 additions & 5 deletions CGI/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ sub expire_calc {
# specifying the date yourself
my($offset);
if (!$time || (lc($time) eq 'now')) {
$offset = 0;
$offset = 0;
} elsif ($time=~/^\d+/) {
return $time;
} elsif ($time=~/^([+-]?(?:\d+|\d*\.\d*))([mhdMy])/) {
$offset = ($mult{$2} || 1)*$1;
return $time;
} elsif ($time=~/^([+-]?(?:\d+|\d*\.\d*))([smhdMy])/) {
$offset = ($mult{$2} || 1)*$1;
} else {
return $time;
return $time;
}
return (time+$offset);
}
Expand Down
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
Version 3.27
1. Applied patch from Steve Taylor that allows checkbox_groups to be
disabled with a new -disabled=> option.

Version 3.26
1. Fixed alternate stylesheet behavior so that it is insensitive to order of declarations.
2. Patch from John Binns to allow users to provide a callback to CGI::Carp.
3. Added "~" as an unreserved character in escape().
4. Patch from Chris Fedde to prevent HTTP_HOST from inhibiting SERVER_PORT in url() generation.
5. Fixed outdated documentation (and behavior) of -language in start_html -script option.
6. Fixed bug in seconds calculation in CGI::Util::expire_calc.

Version 3.25
1. Fixed the link to the Netscape frames page.
Expand Down
9 changes: 8 additions & 1 deletion t/form.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ensure the blib's are in @INC, else we might use the core CGI.pm
use lib qw(. ./blib/lib ./blib/arch);

use Test::More tests => 18;
use Test::More tests => 19;

BEGIN { use_ok('CGI'); };
use CGI (':standard','-no_debug','-tabindex');
Expand Down Expand Up @@ -127,3 +127,10 @@ is(scrolling_list(-name => 'game',
<option selected="selected" value="cribbage">cribbage</option>
</select>',
'scrolling_list()');

is(checkbox_group(-name => 'game',
-Values => [qw/checkers chess cribbage/],
-disabled => ['checkers']),
qq(<label><input type="checkbox" name="game" value="checkers" checked="checked" tabindex="23" disabled='1'/><span style="color:gray">checkers</span></label> <label><input type="checkbox" name="game" value="chess" checked="checked" tabindex="24" />chess</label> <label><input type="checkbox" name="game" value="cribbage" tabindex="25" />cribbage</label>),
'checkbox_group()');

0 comments on commit 11662e4

Please sign in to comment.