Fix Hidden, Radio and Checkbox, which wouldn't allow

a value of zero to be set in them.  It was translated to
the empty string.
This commit is contained in:
Colin Kuskie 2008-05-05 22:20:16 +00:00
parent fd7a1d28a1
commit c930c73d67
6 changed files with 70 additions and 7 deletions

View file

@ -118,7 +118,8 @@ Renders and input tag of type checkbox.
sub toHtml {
my $self = shift;
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->getDefaultValue))) || '';
my $value = $self->getDefaultValue;
$value = defined $value ? $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($value))) : '';
my $checkedText = $self->get("checked") ? ' checked="checked"' : '';
my $idText = $self->get('id') ? ' id="'.$self->get('id').'" ' : '';
return '<input type="checkbox" name="'.($self->get("name")||'').'" value="'.$value.'"'.$idText.$checkedText.' '.($self->get("extras")||'').' />';

View file

@ -97,7 +97,8 @@ Renders an input tag of type hidden.
sub toHtmlAsHidden {
my $self = shift;
my $value = $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($self->getDefaultValue))) || '';
my $value = $self->getDefaultValue;
$value = defined $value ? $self->fixMacros($self->fixQuotes($self->fixSpecialCharacters($value))) : '';
my $idText = $self->get('id') ? ' id="'.$self->get('id').'" ' : '';
return '<input type="hidden" name="'.($self->get("name")||'').'" value="'.$value.'" '.($self->get("extras")||'').$idText.' />'."\n";
}

View file

@ -45,7 +45,7 @@ my $testBlock = [
my $formClass = 'WebGUI::Form::Checkbox';
my $formType = 'Checkbox';
my $numTests = 7 + scalar @{ $testBlock } + 3;
my $numTests = 8 + scalar @{ $testBlock } + 3;
plan tests => $numTests;
@ -101,6 +101,18 @@ $html = join "\n",
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
is( $forms[0]->param('cbox3'), ' ', 'WRONG: whitespace value');
$html = join "\n",
$header,
$formClass->new($session, {
name => 'cbox0',
value => 0,
checked => 1,
})->toHtml,
$footer;
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
is( $forms[0]->param('cbox0'), 0, 'zero is a valid value');
##Test Form Output parsing
WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);

View file

@ -59,11 +59,17 @@ my $testBlock = [
expected => 'EQUAL',
comment => 'white space',
},
{
key => 'Hidden6',
testValue => 0,
expected => 'EQUAL',
comment => 'zero',
},
];
my $formClass = 'WebGUI::Form::Hidden';
my $numTests = 5 + scalar @{ $testBlock } + 1;
my $numTests = 7 + scalar @{ $testBlock } + 1;
plan tests => $numTests;
@ -96,6 +102,20 @@ is($input->value, 'hiddenData', 'Checking default value');
##no need for secondary checking for now
$html = join "\n",
$header,
$formClass->new($session, {
name => 'hiddenZero',
value => 0,
})->toHtml,
$footer;
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
@inputs = $forms[0]->inputs;
$input = $inputs[0];
is($input->name, 'hiddenZero', 'Checking input name for zero input');
is($input->value, 0, 'Checking value for zero input');
##Test Form Output parsing
WebGUI::Form_Checking::auto_check($session, 'Hidden', $testBlock);

View file

@ -45,7 +45,7 @@ my $testBlock = [
my $formClass = 'WebGUI::Form::Radio';
my $formType = 'Radio';
my $numTests = 7 + scalar @{ $testBlock } + 1;
my $numTests = 8 + scalar @{ $testBlock } + 1;
plan tests => $numTests;
@ -100,6 +100,18 @@ $html = join "\n",
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
is( $forms[0]->param('radio2'), ' ', 'WRONG: whitespace value');
$html = join "\n",
$header,
$formClass->new($session, {
name => 'radio3',
value => 0,
checked => 1,
})->toHtml,
$footer;
@forms = HTML::Form->parse($html, 'http://www.webgui.org');
is( $forms[0]->param('radio3'), 0, 'zero is a valid value');
##Test Form Output parsing
WebGUI::Form_Checking::auto_check($session, $formType, $testBlock);

View file

@ -90,8 +90,7 @@ my $properties4 = {
className => 'WebGUI::Asset::Wobject::Product',
url => 'four',
price => 7.77,
title => 'no product number',
description => 'fourth product',
description => 'no title',
};
my $product4 = $root->addChild($properties4);
@ -166,6 +165,24 @@ $productf->setCollateral('Product_feature', 'Product_featureId', {
feature => '25% less code',
});
my $propertiesb = {
className => 'WebGUI::Asset::Wobject::Product',
url => 'benefit_Product',
price => 4.44,
title => 'benefit Product',
description => 'benefit Product',
};
my $productb = $root->addChild($propertiesb);
$productb->setCollateral('Product_benefit', 'Product_benefitId', {
benefit => 'holds mixed nuts',
});
$productb->setCollateral('Product_benefit', 'Product_benefitId', {
benefit => 'automatic sodium monitoring',
});
$tag->commit;
diag "Done.";