Skip to content

Commit

Permalink
Item11966: add default support to radio and checkbox
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@15710 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
SvenDowideit authored and SvenDowideit committed Oct 25, 2012
1 parent 82fccbe commit 9f5a847
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
11 changes: 11 additions & 0 deletions UnitTestContrib/test/unit/InitFormTests.pm
Expand Up @@ -73,6 +73,7 @@ my $testform1 = <<'HERE';
| [[NewWithDefaultOnly][default only]] | text | 20 | | | | is it another plane? |
| Default To Hidden | select | 1 | Defect, Enhancement, Hidden, Other | | | Hidden |
| Default To Enhancement | radio | 1 | Defect, Enhancement, Hidden, Other | | | Enhancement |
| Enhancement Checkbox | checkbox | 4 | Defect, Enhancement, Hidden, Other | | | Enhancement |
HERE
Expand Down Expand Up @@ -502,6 +503,16 @@ Simple description of problem</textarea>', get_formfield( 2, $text )
get_formfield( 13, $text )
);

#| Enhancement Checkbox | checkbox | 4 | Defect, Enhancement, Hidden, Other | | | Enhancement |
$value = 'checked="checked" ';
$value = '' if ( $this->check_dependency('Foswiki,<,1.2') );
$this->assert_html_matches(
'<input type="checkbox" name="EnhancementCheckbox" value="Defect" title="Defect" class="foswikiCheckbox"/>Defect</label></td><td><label><input type="checkbox" name="EnhancementCheckbox" value="Enhancement" '
. $value
. ' title="Enhancement" class="foswikiCheckbox"/>Enhancement</label></td><td><label><input type="checkbox" name="EnhancementCheckbox" value="Hidden" title="Hidden" class="foswikiCheckbox"/>Hidden</label></td><td><label><input type="checkbox" name="EnhancementCheckbox" value="Other" title="Other" class="foswikiCheckbox"/>Other</label>',
get_formfield( 14, $text )
);

return;
}

Expand Down
15 changes: 13 additions & 2 deletions core/lib/Foswiki/Form/Checkbox.pm
Expand Up @@ -58,8 +58,19 @@ sub getOptions {
return $vals;
}

# Checkboxes can't provide a default from the form spec
sub getDefaultValue { return; }
=begin TML
---++ getDefaultValue() -> $value
The default for a select is always the empty string, as there is no way in
Foswiki form definitions to indicate selected values. This defers the decision
on a value to the browser.
=cut

sub getDefaultValue {
my $this = shift;
return ( exists( $this->{default} ) ? $this->{default} : '' );
}

# Checkbox store multiple values
sub isMultiValued { return 1; }
Expand Down
14 changes: 14 additions & 0 deletions core/lib/Foswiki/Form/Radio.pm
Expand Up @@ -102,6 +102,20 @@ sub renderForEdit {
return ( '', CGI::radio_group(%params) );
}

=begin TML
---++ getDefaultValue() -> $value
The default for a select is always the empty string, as there is no way in
Foswiki form definitions to indicate selected values. This defers the decision
on a value to the browser.
=cut

sub getDefaultValue {
my $this = shift;
return ( exists( $this->{default} ) ? $this->{default} : '' );
}

1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Expand Down

0 comments on commit 9f5a847

Please sign in to comment.