FAQ
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?

Search Discussions

  • Michael Reece at Apr 19, 2005 at 7:03 pm
    Nevermind, I found the 'missing_optional_valid => 1' option.
    On 4/19/05 9:55 AM, "Michael Reece" 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@lists.rawmode.org
    http://lists.rawmode.org/mailman/listinfo/catalyst
    --
    michael reece :: web engineer :: mreece@sacbee.com :: (916)321-1249
  • Michael Reece at Apr 19, 2005 at 7:07 pm
    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" wrote:

    Nevermind, I found the 'missing_optional_valid => 1' option.
    On 4/19/05 9:55 AM, "Michael Reece" 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@lists.rawmode.org
    http://lists.rawmode.org/mailman/listinfo/catalyst
    --
    michael reece :: web engineer :: mreece@sacbee.com :: (916)321-1249
  • Michael Reece at Apr 19, 2005 at 7:43 pm
    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" 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" wrote:

    Nevermind, I found the 'missing_optional_valid => 1' option.
    On 4/19/05 9:55 AM, "Michael Reece" 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@lists.rawmode.org
    http://lists.rawmode.org/mailman/listinfo/catalyst
    --
    michael reece :: web engineer :: mreece@sacbee.com :: (916)321-1249

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedApr 19, '05 at 6:55p
activeApr 19, '05 at 7:43p
posts4
users1
websitecatalystframework.org
irc#catalyst

1 user in discussion

Michael Reece: 4 posts

People

Translate

site design / logo © 2021 Grokbase