Skip to content

Commit

Permalink
Item10345: use defaults for parameters 'alttext' and 'default' (empty…
Browse files Browse the repository at this point in the history
… string) if not passed explicitly

git-svn-id: http://svn.foswiki.org/trunk@10689 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
ArthurClemens authored and ArthurClemens committed Feb 12, 2011
1 parent 524378f commit b452f4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion UnitTestContrib/test/unit/Fn_FORMFIELD.pm
Expand Up @@ -69,10 +69,11 @@ sub test_FORMFIELD_default {
$result = $topicObject->expandMacros(
'%FORMFIELD{"Priscilla" default="Clementina"}%');
$this->assert_str_equals('Clementina', $result);

# with format
$result = $topicObject->expandMacros(
'%FORMFIELD{"Priscilla" format="Beauty queen: $value" default="Clementina"}%');
$this->assert_str_equals('Clementina', $result);

}

# alttext="..." Text shown when field is not found in the form
Expand Down Expand Up @@ -111,10 +112,20 @@ sub test_FORMFIELD_format {
'%FORMFIELD{"Priscilla" format="Beauty queen: $value" default="Clementina"}%');
$this->assert_str_equals('Clementina', $result);

# with 'default' default (empty string)
$result = $topicObject->expandMacros(
'%FORMFIELD{"Priscilla" format="Beauty queen: $value"}%');
$this->assert_str_equals('', $result);

# with alttext
$result = $topicObject->expandMacros(
'%FORMFIELD{"Ffiona" format="Beauty queen: $value" alttext="Candida" default="Clementina"}%');
$this->assert_str_equals('Candida', $result);

# with default alttext (empty string)
$result = $topicObject->expandMacros(
'%FORMFIELD{"Ffiona" format="Beauty queen: $value"}%');
$this->assert_str_equals('', $result);
}

# topic="..." Topic where form data is located. May be of the form Web.<nop>TopicName
Expand Down
6 changes: 3 additions & 3 deletions core/lib/Foswiki/Render.pm
Expand Up @@ -912,8 +912,8 @@ sub renderFORMFIELD {

my $formField = $params->{_DEFAULT};
return '' unless defined $formField;
my $altText = $params->{alttext};
my $default = $params->{default};
my $altText = $params->{alttext} || '';
my $default = $params->{default} || '';
my $rev = $params->{rev} || '';
my $format = $params->{format};

Expand Down Expand Up @@ -950,7 +950,7 @@ sub renderFORMFIELD {
if ( $title eq $formField || $name eq $formField ) {
$found = 1;
my $value = $field->{value};
$text = $default if ( !length($value) && defined($default));
$text = $default if !length($value);
$text =~ s/\$title/$title/go;
$text =~ s/\$value/$value/go;
$text =~ s/\$name/$name/g;
Expand Down

0 comments on commit b452f4a

Please sign in to comment.