From 55893c00504462300c26786ee51b6b50c4f22da8 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 23 Aug 2012 15:00:09 -0700 Subject: [PATCH] Fix Crud's pPFFP and commit the results this time so that I don't lose it and have to explain why I'm redoing 4 hours of painstaking form work with testing. Fixes bug #12382. --- docs/changelog/7.x.x.txt | 3 ++- lib/WebGUI/Crud.pm | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 0bb2748c6..46092060f 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.10.27 -- fixed #12379: userImport documentation error + - fixed #12379: userImport documentation error + - fixed #12382: WebGUI::Crud does not work with all form types 7.10.26 - fixed: Template diagnostics when called without a session asset. diff --git a/lib/WebGUI/Crud.pm b/lib/WebGUI/Crud.pm index 9c502b7f2..96b6f684c 100644 --- a/lib/WebGUI/Crud.pm +++ b/lib/WebGUI/Crud.pm @@ -24,6 +24,7 @@ use Clone qw/clone/; use WebGUI::DateTime; use WebGUI::Exception; use WebGUI::Utility; +use WebGUI::Pluggable; private objectData => my %objectData; readonly session => my %session; @@ -991,20 +992,28 @@ sub update { =head2 updateFromFormPost ( ) -Calls update() on any properties that are available from $session->form. Returns 1 on success. +Calls update() on all properties that the object expects. =cut sub updateFromFormPost { - my $self = shift; - my $session = $self->session; - my $form = $session->form; - my %data; - my $properties = $self->crud_getProperties($session); - foreach my $property ($form->param) { - $data{$property} = $form->get($property, $properties->{$property}{fieldType}, $properties->{$property}{defaultValue}); - } - return $self->update(\%data); + my $self = shift; + my $session = $self->session; + my $form = $session->form; + my $data = $self->get(); + my $properties = $self->crud_getProperties($session); + PROPERTY: foreach my $property (keys %{ $properties }) { + my $fieldType = 'WebGUI::Form::'.ucfirst $properties->{$property}{fieldType}; + my $control = eval { WebGUI::Pluggable::instanciate($fieldType, "new", [ $self->session, { name => $property, } ]) }; + if ($@) { + $self->session->errorHandler->error($@); + next PROPERTY; + } + next PROPERTY if ! $control->isInRequest; + $data->{$property} = + $form->get($property, $properties->{$property}{fieldType}, $properties->{$property}{defaultValue}); + } + return $self->update($data); }