[html-formfu] combo box equivalent
Malcolm
mjh-formfu at liminalflux.net
Sun Sep 14 19:04:46 BST 2008
On Monday 08 September 2008, Carl Franks wrote:
> > I wonder if it should (have the option to) throw an error if they are
> > different. So the form could go back to the user with a "which did you
> > mean?" I'm not sure if that makes sense from a useability perspective
> > though.
> Maybe it would just be best to return an error is both are submitted,
> regardless of value.
That sounds like a reasonable approach to me.
> > The only thing I've run into is trying to set the options list
> > programmatically. Calling $element->options doesn't seem to have an
> > effect as the form is already created (via FormConfig) from the yml.
>
> Make sure you call $form->process() after calling $element->options.
I did. That doesn't seem to have any effect. Once $self->elements is populated,
there doesn't seem to be anything that regenerates the options.
I haven't written tests yet, but the following edit seems to work for allowing
callbacks.
I don't think I like the interface though, it seems too error prone.
Ie.
elements:
- type: ComboBox
label: Country
name: country
values: Model::countries
or:
elements:
- type: ComboBox
label: Country
name: country
values:
- USA
- UK
- Canada
work, but:
elements:
- type: ComboBox
label: Country
name: country
values: USA UK Canada
gives the somewhat confusing: "values argument (USA UK Canada) does not seem to be a function" error.
Index: lib/HTML/FormFu/Element/_Group.pm
===================================================================
--- lib/HTML/FormFu/Element/_Group.pm (revision 1204)
+++ lib/HTML/FormFu/Element/_Group.pm (working copy)
@@ -239,8 +239,17 @@
my @values;
if ( defined $arg ) {
- eval { @values = @$arg };
- croak "values argument must be an array-ref" if $@;
+ if (not ref $arg)
+ {
+ no strict 'refs';
+ eval {@values = *$arg->()};
+ croak "values argument ($arg) does not seem to be a function" if $@;
+ }
+ else
+ {
+ eval { @values = @$arg };
+ croak "values argument must be an array-ref" if $@;
+ }
}
More information about the HTML-FormFu
mailing list