Skip to content

Commit 55893c0

Browse files
committedAug 23, 2012
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.
1 parent 4d30562 commit 55893c0

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed
 

‎docs/changelog/7.x.x.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
7.10.27
2-
- fixed #12379: userImport documentation error
2+
- fixed #12379: userImport documentation error
3+
- fixed #12382: WebGUI::Crud does not work with all form types
34

45
7.10.26
56
- fixed: Template diagnostics when called without a session asset.

‎lib/WebGUI/Crud.pm

+19-10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use Clone qw/clone/;
2424
use WebGUI::DateTime;
2525
use WebGUI::Exception;
2626
use WebGUI::Utility;
27+
use WebGUI::Pluggable;
2728

2829
private objectData => my %objectData;
2930
readonly session => my %session;
@@ -991,20 +992,28 @@ sub update {
991992

992993
=head2 updateFromFormPost ( )
993994
994-
Calls update() on any properties that are available from $session->form. Returns 1 on success.
995+
Calls update() on all properties that the object expects.
995996
996997
=cut
997998

998999
sub updateFromFormPost {
999-
my $self = shift;
1000-
my $session = $self->session;
1001-
my $form = $session->form;
1002-
my %data;
1003-
my $properties = $self->crud_getProperties($session);
1004-
foreach my $property ($form->param) {
1005-
$data{$property} = $form->get($property, $properties->{$property}{fieldType}, $properties->{$property}{defaultValue});
1006-
}
1007-
return $self->update(\%data);
1000+
my $self = shift;
1001+
my $session = $self->session;
1002+
my $form = $session->form;
1003+
my $data = $self->get();
1004+
my $properties = $self->crud_getProperties($session);
1005+
PROPERTY: foreach my $property (keys %{ $properties }) {
1006+
my $fieldType = 'WebGUI::Form::'.ucfirst $properties->{$property}{fieldType};
1007+
my $control = eval { WebGUI::Pluggable::instanciate($fieldType, "new", [ $self->session, { name => $property, } ]) };
1008+
if ($@) {
1009+
$self->session->errorHandler->error($@);
1010+
next PROPERTY;
1011+
}
1012+
next PROPERTY if ! $control->isInRequest;
1013+
$data->{$property} =
1014+
$form->get($property, $properties->{$property}{fieldType}, $properties->{$property}{defaultValue});
1015+
}
1016+
return $self->update($data);
10081017
}
10091018

10101019

0 commit comments

Comments
 (0)
Please sign in to comment.