[Catalyst] No database defaults with FormHandler and DBIC

Martin Řehák rehak at tekkirk.org
Sat Dec 10 16:17:46 GMT 2016


Hi,

I understand that there is a complicated solution. I am looking for
the simplest way.

Doc says:

<snip>
For forms where you pass in an 'item' (usually a database row object),
the values in that object will be used preferentially; if an accessor
exists in the 'item' object, then the defaults won't be used. (If an
accessor doesn't exist, the defaults *will* be used.)

$form->process( item => $row, params => {} );

For the above call the 'default' on the field will not be used, which is
usually what you want.
</snip>

What is the easiest way how to get defaults going from the database
schema into a form, please? Is process() function able to propagate
defaults from $row into $form? How to achieve that?

Regards
-- 
Martin

On 2016.12.10 16:51:52 +0100, LNATION . wrote:
> My email coding has some syntax errors, apologies.
> 
> On Sat, Dec 10, 2016 at 4:50 PM, LNATION . <thisusedtobeanemail at gmail.com>
> wrote:
> 
> > and then make a role role
> >
> > has default_column_spec => ( ...)
> >
> > before render => sub {
> >       while (my ($field, $default) = each %{ $_[0]->default_column_spec}{
> >           unless ($_[0]->field($filed)->value) { # mayb editing
> >                 $_[0]->field('$field)->value($default);
> >            }
> >       }
> > }
> >
> >
> > On Sat, Dec 10, 2016 at 4:41 PM, LNATION . <thisusedtobeanemail at gmail.com>
> > wrote:
> >
> >> maybe something like ......
> >>
> >>     my $columns = $result->result_source->columns_info;
> >>     my %default_form_spec;
> >>     for my $name (keys %{$columns}){
> >>          if (my $default = $columns->{$name}->{default_value}) {
> >>              $default_form_spec{  $name } = $default;
> >>          }
> >>     }
> >>
> >>
> >>
> >

> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/




More information about the Catalyst mailing list