Skip to content

Commit 71ff81a

Browse files
jmadleroalders
authored andcommitted
Permit passing an empty or false value to second param (value) of
tick(). This resolves issue #203
1 parent 582aa4c commit 71ff81a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/WWW/Mechanize.pm

+13-3
Original file line numberDiff line numberDiff line change
@@ -2069,9 +2069,12 @@ sub set_visible {
20692069
=head2 $mech->tick( $name, $value [, $set] )
20702070
20712071
"Ticks" the first checkbox that has both the name and value associated
2072-
with it on the current form. Dies if there is no named check box for
2073-
that value. Passing in a false value as the third optional argument
2074-
will cause the checkbox to be unticked.
2072+
with it on the current form. If there is no value to the input, just
2073+
pass an empty string or undef as the value. Dies if there is no named
2074+
checkbox for the value given, if a value is given. Passing in a false
2075+
value as the third optional argument will cause the checkbox to be
2076+
unticked. The third value does not need to be set if you wish to
2077+
merely tick the box.
20752078
20762079
=cut
20772080

@@ -2084,6 +2087,13 @@ sub tick {
20842087
# loop though all the inputs
20852088
my $index = 1;
20862089
while ( my $input = $self->current_form->find_input( $name, 'checkbox', $index ) ) {
2090+
# Sometimes the HTML is malformed and there is no value for the check
2091+
# box, so we just return if the value passed is an empty string
2092+
# (and the form input is found)
2093+
if ($value eq '') {
2094+
$input->value($set ? $value : undef);
2095+
return;
2096+
}
20872097
# Can't guarantee that the first element will be undef and the second
20882098
# element will be the right name
20892099
foreach my $val ($input->possible_values()) {

0 commit comments

Comments
 (0)