[html-formfu] combo box equivalent

Carl Franks fireartist at gmail.com
Mon Sep 15 10:56:35 BST 2008


2008/9/14 Malcolm <mjh-formfu at liminalflux.net>:
> On Monday 08 September 2008, Carl Franks wrote:

I haven't had time to go through this properly, so I'm just briefly
addressing a couple of points here...

>> > 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.

use HTML::FormFu;

my $form = HTML::FormFu->new;

$form->populate({
    elements => [
        {
            type => 'ComboBox',
            name => 'foo',
            options => [
                [ 1, 'one' ],
                [ 2, 'two' ],
            ],
        },
    ],
});

$form->process;

$form->get_element({ type => 'ComboBox' })->options([
    [ 3, 'three' ],
    [ 4, 'four' ],
]);

$form->process;

print $form;

###

The above example works as expected - with the select menu containing
'3' and '4' options.

The only thing I can think of, is that you're calling options()
directly on $combobox->elements->[0]
rather than on the combobox - don't do this - you should consider the
combobox a blackbox with regards its child elements.

If that's not it, I'll need to see some code.

> 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.

That is equivalent to:
    values: 'USA UK Canada'

I think you mean:
    values: ['USA', 'UK', 'Canada']

Carl



More information about the HTML-FormFu mailing list