[html-formfu] nested params merged

Jonas Alves jonas.alves at gmail.com
Tue Oct 30 22:47:52 GMT 2007


On 30/10/2007, Carl Franks <fireartist at gmail.com> wrote:
> I've merged the nested-params branch back into trunk.
>
> Although there's extensive new tests, I haven't tried it out with a
> real application yet - so there may be some teething issues.
> Documentation's still needing done.
>
> Some of the template files have been changed - as they need to use
> 'nested_name' now rather than 'name'. (The next thing I'm going to
> work on will make it easier to use templates and easier to upgrade
> HTML::FormFu).
>
> To expand on the examples in my last mail...
>
> You can set a Form or Block elements nested_name().
> You still just set name() on fields.
>
> $field->nested_name() returns the full name that'll be used in the form markup.
>
> If you set $form->nested_subscript(1), elements names will have the
> form "foo[bar][baz]" instead of "foo.bar.baz"
>
> If a field-name or intermediary nested name is an integer, the data
> structure returned by $form->params() or $form->param() will be an
> array-ref:
>
> "foo.bar.0" => 1
> "foo.bar.1" => 2
>
> If you're using any of the Callback processors, or have written your
> own processors (constraints, validators, etc) - they generally get the
> relevant input value as their 1st argument, and the $params hash-ref
> as their 2nd argument.
> Because the $params hash-ref is no longer a single-depth hash, but may
> contain nested structures, you should no longer simply do stuff like
> this:
>     $foo = $params->{foo};
>     $params->{foo} = $foo;
>     if ( exists $params->{foo} ) { }
>
> You should instead use the following helper methods:
>
>     $foo = $self->get_nested_hash_value(
>         $params, $nested_name );
>
>     $self->set_nested_hash_value(
>         $params, $nested_name, $value );
>
>     if ( $self->nested_hash_key_exists(
>         $params, $nested_name ) )
>     { }
>
> Um, that's all I can think of for now...
>
> Carl
>

Hi Carl,
Great work. :)
May I know if you pretend to implement the validation without the dot
parameters as I suggested? If not, is it because you don't like it? If
is because you don't want to wast time on it, will you accept a patch?

Cheers,
-- 
Jonas



More information about the HTML-FormFu mailing list