Skip to content

Commit

Permalink
Permit passing an empty or false value to second param (value) of
Browse files Browse the repository at this point in the history
tick().  This resolves issue #203
  • Loading branch information
jmadler authored and oalders committed Jul 5, 2022
1 parent 582aa4c commit 71ff81a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/WWW/Mechanize.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2069,9 +2069,12 @@ sub set_visible {
=head2 $mech->tick( $name, $value [, $set] )
"Ticks" the first checkbox that has both the name and value associated
with it on the current form. Dies if there is no named check box for
that value. Passing in a false value as the third optional argument
will cause the checkbox to be unticked.
with it on the current form. If there is no value to the input, just
pass an empty string or undef as the value. Dies if there is no named
checkbox for the value given, if a value is given. Passing in a false
value as the third optional argument will cause the checkbox to be
unticked. The third value does not need to be set if you wish to
merely tick the box.
=cut

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

0 comments on commit 71ff81a

Please sign in to comment.