[html-formfu] select options doesn't round-trip

Geoffrey D. Bennett g at netcraft.com.au
Sun Sep 21 13:58:03 BST 2008


Hi there,

It seems that HTML::FormFu::Element::_Group::options() doesn't
round-trip if empty_first is being used.

Ie. this code results in the first option being doubled:

  my $my_field = $form->get_element({name => "my_field"});
  $my_field->options($my_field->options);

My use case is that I have defined a new element type SelectFromTable
which inherits from Select and gets used something like this to
auto-populate the options from a database table:

  - type: SelectFromTable
    name: org_type_id
    label: Organisation Type
    empty_first: 1
    empty_first_label: Select an Organisation Type
    model_name: DB::OrgType
    cond:
      active: t
    attrs:
      order_by: name
    constraints:
      - Required

Within my Catalyst controller though, in one particular instance I
want to add an extra selection possibility, something like this:

  my $my_field = $form->get_element({name => "my_field"});
  my @options = @{$my_field->options};
  $my_field->options([
    @options,
    [ "Extra", "Option" ],
  ]);

I'm probably going to define a new element type so this will end up
being irrelevant for me, but it seemed like a bug worth reporting
anyway.

In the meantime, the workaround is easy:

  shift @options if $options[0]->{value} eq "";

Regards,
-- 
Geoffrey D. Bennett, RHCE, RHCX               mailto:g at netcraft.com.au
Senior Systems Engineer                          sip:g at netcraft.com.au
NetCraft Australia Pty Ltd        http://www.netcraft.com.au/geoffrey/



More information about the HTML-FormFu mailing list