From 1ec0ec5961b1cf22450fca193b7dfe92cab907c0 Mon Sep 17 00:00:00 2001 From: Martin Kamerbeek Date: Thu, 28 May 2009 16:31:45 +0000 Subject: [PATCH] - Fixed a bug in thingy which caused the defaultValue property for some list form elements to be ignored. - Fixed a race condition introduced in a previous commit. --- docs/changelog/7.x.x.txt | 2 ++ lib/WebGUI/Asset/Wobject/Thingy.pm | 28 +++++++++++++++++----------- lib/WebGUI/Form/List.pm | 2 +- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 9de9d43de..462a7008e 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -23,6 +23,8 @@ elements (eg. check lists) only one of the selected elements was taken into account in the search query. ( Martin Kamerbeek / Oqapi ) - fixed #10439: Call to insufficient is wrong (lrobinson / Orchard Solutions ) + - fixed a bug in Thingy where the defaultValue of multi value form elements + would not be applied ( Martin Kamerbeek / Oqapi ) 7.7.7 - Added EMS Schedule table diff --git a/lib/WebGUI/Asset/Wobject/Thingy.pm b/lib/WebGUI/Asset/Wobject/Thingy.pm index ef4c623e2..0e13cfd5c 100644 --- a/lib/WebGUI/Asset/Wobject/Thingy.pm +++ b/lib/WebGUI/Asset/Wobject/Thingy.pm @@ -939,12 +939,12 @@ A hashref containing the properties of this field. sub getFormElement { my $self = shift; - return $self->getFormPlugin( @_ )->toHtml; + return $self->getFormPlugin( @_, 1 )->toHtml; } #------------------------------------------------------------------- -=head2 getFormPlugin ( properties ) +=head2 getFormPlugin ( properties, [ useFormPostData ] ) Returns an instanciated WebGUI::Form::* plugin. @@ -952,11 +952,17 @@ Returns an instanciated WebGUI::Form::* plugin. The properties to configure the form plugin with. The fieldType key should contain the type of the form plugin. +=head3 useFormPostData + +If set to true, the value of the form element will be set to the data posted by it if available. + =cut sub getFormPlugin { - my $self = shift; - my $data = shift; + my $self = shift; + my $data = shift; + my $useFormPostData = shift; + my %param; my $session = $self->session; my $db = $session->db; @@ -982,19 +988,19 @@ sub getFormPlugin { } if ( WebGUI::Utility::isIn( $data->{fieldType}, qw(SelectList CheckList SelectBox Attachments) ) ) { - my @defaultValues; - if ( $self->session->form->param($name) && !$data->{value} ) { - @defaultValues = $session->form->process( $name, $data->{fieldType} ); + my @values; + if ( $useFormPostData && $self->session->form->param($name) ) { + $param{ value } = [ $session->form->process( $name, $data->{fieldType} ) ]; } - else { + elsif ( $data->{ value } ) { foreach (split(/\n/x, $data->{value})) { s/\s+$//x; # remove trailing spaces - push(@defaultValues, $_); + push(@values, $_); } + $param{value} = \@values; } - $param{value} = \@defaultValues; } - elsif ( $self->session->form->param($name) && !$data->{value} ) { + elsif ( $useFormPostData && $self->session->form->param($name) ) { $param{value} = $session->form->process( $name, $data->{fieldType} ); } diff --git a/lib/WebGUI/Form/List.pm b/lib/WebGUI/Form/List.pm index f46962ad7..14d6bde7b 100644 --- a/lib/WebGUI/Form/List.pm +++ b/lib/WebGUI/Form/List.pm @@ -245,7 +245,7 @@ sub getDefaultValue { } else { $value =~ s/\r//g; - @values = split "\n", $value; + @values = split /\n/, $value; } } }