[html-formfu] model_stash + model_config with ComboBox element

Jens Schwarz blacky6767 at gmx.de
Tue Jan 27 12:46:53 GMT 2009


Hi,

some weeks ago Carl gave me this useful hint (see below) for populating Select elements. Works fine with Select elements. Now I tried to adopt this for my ComboBox but failed (just think of the example below being a ComboBox instead of a Select): The result is that when I call the edit action in my Catalyst controller, the genre saved in the recordset is displayed in the genres_text part of the ComboBox - even if the genre would be available in genres_select.

Do I have to handle ComboBoxes in another way than Selects to populate them?

> 2008/12/4 Jens Schwarz <blacky6767 at gmx.de>:
> >    my @genreobj = $c->model('My::Genres')->all();
> >    my @genres;
> >    foreach my $g (@genreobj) {
> >      push(@genres, [$g->id, $g->name]);
> >    }
> >    my $select = $form->get_element({name => 'genres'});
> >    $select->options(\@genres);
> 
> BTW, you could get rid of all that code to populate $select->options()
> by making sure the appropriate Model is in your form stash, by setting
> this in your cat application config:
> 
>     'Controller::HTML::FormFu':
>       model_stash:
>         schema: My
> 
> Then modifying the Select field in your form config:
> 
>     type: Select
>     name: genres
>     model_config:
>         resultset: Genres
> 
> That will also have the benefit of populating the Select menu every
> time the form's built - so if you add an AutoSet constraint to the
> field, it'll check whether the user-submitted value was a valid
> option, when you call $form->submitted_and_valid().
> 
> Carl
-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger



More information about the HTML-FormFu mailing list