[Catalyst] Empty strings and FormValidator

Michael Reece mreece at sacbee.com
Tue Apr 19 19:44:01 CEST 2005


Rewriting Class::DBI::FromForm's _run_update as:

--- FromForm.pm.orig    Tue Apr 19 10:34:17 2005
+++ FromForm.pm Tue Apr 19 10:48:27 2005
@@ -66,9 +66,11 @@
 
 sub _run_update {
     my ( $me, $them, $results ) = @_;
+    my $valid = $results->valid;
     foreach my $col ( $them->columns('All') ) {
         next if $col eq $them->primary_column;
-        if ( defined( my $val = $results->valid($col) ) ) {
+        if ( exists $valid->{$col} ) {
+            my $val = $valid->{$col};
             $them->$col($val);
         }
     }


Fixes the problem.




On 4/19/05 10:07 AM, "Michael Reece" <mreece at sacbee.com> wrote:

> Well, not exactly .. That puts the 'missing' optional fields back into valid
> as undef, but Class::DBI::FromForm's _run_update only sets $them->$col($val)
> if the value is defined ..
> 
> I am still open to suggestions on how to get these packages to play nice
> together, if someone else has already solved this problem.
> 
> On 4/19/05 10:03 AM, "Michael Reece" <mreece at sacbee.com> wrote:
> 
>> Nevermind, I found the 'missing_optional_valid => 1' option.
>> 
>> On 4/19/05 9:55 AM, "Michael Reece" <mreece at sacbee.com> wrote:
>> 
>>> Using Catalyst::Plugin::FormValidator and Class::DBI::FromForm, I noticed
>>> that 'cleared' values (empty string) are not saved.
>>> 
>>> This is because Data::FormValidator->check deletes empty values from the
>>> 'valid' hash:
>>> 
>>> (in Data/FormValidator/Results.pm, sub _process)
>>> 
>>>   delete $valid{$field} unless (defined $valid{$field} and length
>>> $valid{$field});
>>> 
>>> so these cleared fields are never updated by update_from_form.
>>> 
>>> Has anyone dealt with this problem or have suggestions?
>>> 
>>> 
>>> 
>>> _______________________________________________
>>> Catalyst mailing list
>>> Catalyst at lists.rawmode.org
>>> http://lists.rawmode.org/mailman/listinfo/catalyst
>>> 

-- 
michael reece :: web engineer :: mreece at sacbee.com :: (916)321-1249





More information about the Catalyst mailing list