[html-formfu] model_stash + model_config with ComboBox element
Jens Schwarz
blacky6767 at gmx.de
Mon Feb 16 10:19:53 GMT 2009
-------- Original-Nachricht --------
> Datum: Thu, 29 Jan 2009 09:17:15 +0000
> Von: Carl Franks <fireartist at gmail.com>
> An: "HTML Form Creation, Rendering and Validation Framework" <html-formfu at lists.scsys.co.uk>
> Betreff: Re: [html-formfu] model_stash + model_config with ComboBox element
> Well, my blind guess didn't work, so without some form + dbic config,
> I don't have much more to go on.
>
> I've updated the files
> t/default_values/belongs_to_lookup_table_combobox.t
> t/default_values/belongs_to_lookup_table_combobox.yml
> to ensure a ComboBox works as expected, being populated with
> options_from_model(), and then selecting the correct menu option with
> default_values(). (svn r1304)
Hi,
again sorry for the delay. I now have found the time to put together an example which hopefully can help helping me :)
The difference between the the Select example of December 2008 (http://lists.scsys.co.uk/pipermail/html-formfu/2008-December/001575.html) and this ComboBox is, that I want the genrename be _copied_ into the bands table rather than being a relationship: It should be possible that a genre 'foo' exists in a band record which does not exist (anymore/yet) in the genres table. So I build the ComboBox myself rather than using "model_config: resultset: Genres".
edit.yml (of the bands Controller):
-----------------------------------
- type: ComboBox
name: genres
label: select genre oder enter one
bands.pm (Schema):
------------------
package myapp::Schema::Bands;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("Bands");
__PACKAGE__->add_columns(
"id",
{
data_type => "INT",
default_value => undef,
is_auto_increment => 1,
is_nullable => 0,
size => 11,
},
"name",
{
data_type => "TEXT",
default_value => undef,
is_nullable => 1,
size => 65535,
},
"genre",
{
data_type => "TEXT",
default_value => undef,
is_nullable => 1,
size => 65535,
},
);
__PACKAGE__->set_primary_key("id");
genres.pm (Schema):
-------------------
package myapp::Schema::Genres;
use strict;
use warnings;
use base 'DBIx::Class';
__PACKAGE__->load_components("Core");
__PACKAGE__->table("Genres");
__PACKAGE__->add_columns(
"id",
{
data_type => "INT",
default_value => undef,
is_auto_increment => 1,
is_nullable => 0,
size => 11,
},
"name",
{
data_type => "TEXT",
default_value => undef,
is_nullable => 1,
size => 65535,
},
);
__PACKAGE__->set_primary_key("id");
bands.pm (Controller):
----------------------
sub edit :Local :FormConfig {
my ( $self, $c, @args ) = @_;
my $bands = $c->model('myapp::Bands')->find($args[0]);
my $form = $c->stash->{form};
if ($form->submitted_and_valid) {
...
}
else {
my @allGenres = $c->model('myapp::Genres')->all();
my @genres;
foreach (@allGenres) {
push(@genres, [$_->name, $_->name]);
}
my $combo = $form->get_field({ name => 'genres' });
$combo->options(\@genres);
...
$form->model->default_values($bands);
$form->process();
}
}
Jens
--
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01
More information about the HTML-FormFu
mailing list