Skip to content

Commit 49a364d

Browse files
jmadlersimbabque
authored andcommitted
Permit passing an empty or false value to second param (value) of
tick(). This resolves issue #203
1 parent 95e1698 commit 49a364d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/WWW/Mechanize.pm

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,9 +2036,12 @@ sub set_visible {
20362036
=head2 $mech->tick( $name, $value [, $set] )
20372037
20382038
"Ticks" the first checkbox that has both the name and value associated
2039-
with it on the current form. Dies if there is no named check box for
2040-
that value. Passing in a false value as the third optional argument
2041-
will cause the checkbox to be unticked.
2039+
with it on the current form. If there is no value to the input, just
2040+
pass an empty string or undef as the value. Dies if there is no named
2041+
checkbox for the value given, if a value is given. Passing in a false
2042+
value as the third optional argument will cause the checkbox to be
2043+
unticked. The third value does not need to be set if you wish to
2044+
merely tick the box.
20422045
20432046
=cut
20442047

@@ -2051,6 +2054,13 @@ sub tick {
20512054
# loop though all the inputs
20522055
my $index = 1;
20532056
while ( my $input = $self->current_form->find_input( $name, 'checkbox', $index ) ) {
2057+
# Sometimes the HTML is malformed and there is no value for the check
2058+
# box, so we just return if the value passed is an empty string
2059+
# (and the form input is found)
2060+
if ($value eq '') {
2061+
$input->value($set ? $value : undef);
2062+
return;
2063+
}
20542064
# Can't guarantee that the first element will be undef and the second
20552065
# element will be the right name
20562066
foreach my $val ($input->possible_values()) {

0 commit comments

Comments
 (0)