[html-formfu] get_element method

Carl Franks fireartist at gmail.com
Tue Sep 16 12:28:36 BST 2008


2008/9/16 Dermot <paikkos at googlemail.com>:
> Hi,
>
> I cannot get the get_element method to work on my installation.
>
> Catalyst::Controller::HTML::FormFu
>
>        my $select = $form->get_element({type => 'Select'});  # There
> is only one select element in my yml form
>        $c->log->debug("Select=",$select);
>        $select->options(\@roles);

You need get_all_element(), which does a recursive search.

get_element() only searches elements which are direct children of
whatever you're searching.
(and if you're searching a form with auto_fieldset(1), then
get_element() will only ever return the fieldset)


> I have had this problem in a few different controllers in my Cat app.
> What I have been doing is
>
>        my $select = $form->get_all_elements({type => 'Select'});
>        $c->log->debug("Select=",join ' ', $select->[0]);
>        $select->[0]->options(\@roles);

You want get_all_element() - not get_all_elements()

The first returns a single element - the second returns an arrayref of
elements, even if there's only 1 to return.

Carl



More information about the HTML-FormFu mailing list