From 7f2b6dfc83429f61cc39660db58d9004a5f1a9eb Mon Sep 17 00:00:00 2001 From: Graham Knop Date: Fri, 3 Apr 2009 00:40:23 +0000 Subject: [PATCH] fix allowEmpty and bugs it caused --- lib/WebGUI/Asset.pm | 2 +- lib/WebGUI/AssetAspect/RssFeed.pm | 1 + lib/WebGUI/Form/Control.pm | 3 +++ lib/WebGUI/Form/List.pm | 21 ++++++++++----------- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 7b031cfce..c04b366bf 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -2340,7 +2340,7 @@ sub update { # next unless (exists $properties->{$property} || exists $definition->{properties}{$property}{defaultValue}); # skip a property unless it was specified to be set by the properties field next unless (exists $properties->{$property}); - my $propertyDefinition = $definition->{property}{$property}; + my $propertyDefinition = $definition->{properties}{$property}; # skip a property if it has the display only flag set next if ($propertyDefinition->{displayOnly}); diff --git a/lib/WebGUI/AssetAspect/RssFeed.pm b/lib/WebGUI/AssetAspect/RssFeed.pm index 21dd73a36..ef01ccbd9 100644 --- a/lib/WebGUI/AssetAspect/RssFeed.pm +++ b/lib/WebGUI/AssetAspect/RssFeed.pm @@ -115,6 +115,7 @@ sub definition { }, feedHeaderLinks => { fieldType => "checkList", + allowEmpty => 1, defaultValue => "rss\natom", tab => "rss", options => do { diff --git a/lib/WebGUI/Form/Control.pm b/lib/WebGUI/Form/Control.pm index 270b02a34..d16ac5e5f 100644 --- a/lib/WebGUI/Form/Control.pm +++ b/lib/WebGUI/Form/Control.pm @@ -196,6 +196,9 @@ sub definition { idPrefix=>{ defaultValue=>undef }, + allowEmpty=>{ + defaultValue => 0, + }, }); return $definition; } diff --git a/lib/WebGUI/Form/List.pm b/lib/WebGUI/Form/List.pm index a10765b15..f46962ad7 100644 --- a/lib/WebGUI/Form/List.pm +++ b/lib/WebGUI/Form/List.pm @@ -220,7 +220,7 @@ sub getValue { @values = $self->session->form->param($self->get("name")); } } - if (scalar @values < 1) { + if (scalar @values < 1 && ! $self->get('allowEmpty')) { @values = $self->getDefaultValue; } return wantarray ? @values : join("\n",@values); @@ -262,18 +262,17 @@ Returns the either the "value" ore "defaultValue" passed in to the object in tha sub getOriginalValue { my $self = shift; my @values = (); - foreach my $value ($self->get("value")) { - if (scalar @values < 1 && defined $value) { - if (ref $value eq "ARRAY") { - @values = @{$value}; - } - else { - $value =~ s/\r//g; - @values = split "\n", $value; - } + my $value = $self->get("value"); + if (defined $value) { + if (ref $value eq "ARRAY") { + @values = @{$value}; + } + else { + $value =~ s/\r//g; + @values = split "\n", $value; } } - if (@values) { + if (@values || ($self->get('allowEmpty') && defined $value) ) { return wantarray ? @values : join("\n",@values); }