[html-formfu] Taking default value when not supplied in query
(plaintext)
Carl Franks
fireartist at gmail.com
Sat Oct 9 16:46:35 GMT 2010
On 9 October 2010 17:16, Wicked bits <wickedbits at gmail.com> wrote:
> Sorry for the mangled post, here it is plainly:
>
> When FormFu processes a query that contains only some of the defined
> fields, how can the fields that don't appear in the query have their
> default value(s) in $form->params?
I think this should work...
You'll need a custom plugin that would be attached to the Select elements:
package MyCustomPlugin;
use base 'HTML::FormFu::Plugin';
sub post_process {
my ($self) = @_;
my $field = $self->parent;
return if !$field->retain_default;
my $nested_name = $field->nested_name;
return if $form->valid( $nested_name );
$self->form->add_valid(
$nested_name,
$field->default,
);
return;
}
1;
Then to automatically attach this plugin to all Select elements, you could do:
---
default_args:
elements:
Select:
plugins: '+MyCustomPlugin'
And if you're using Catalyst::Controller::HTML::FormFu, you can use this:
http://search.cpan.org/~cfranks/HTML-FormFu-0.08002/lib/HTML/FormFu/Manual/Cookbook.pod#Application-wide_default_values
carl
More information about the HTML-FormFu
mailing list