[Catalyst] HTML::Widget, callback constraint, and multiple records per form
Jason Kohles
email at jasonkohles.com
Fri Sep 1 22:58:45 CEST 2006
On 9/1/06, Ben Hopkins <hopkins.ben at gmail.com> wrote:
> Boy is my face red!
>
> What a stupid mistake! Thanks for noticing it.
>
> Hmmm. Makes me think now. The see_if_exists subroutine now gets the value
> in the form, but doesn't have any context (to do a
> $c->model('electionsDB::County')->find... call). If I made
> a subroutine that returns a coderef to a snippet that has the context in it
> ...
>
>
You can work around that pretty easily, by making the callback an
inline sub ref...
sub make_counties_widget {
my ($self, $c) = @_;
my $w = $c->widget('county_form')->method('post');
for my $f (1..10) {
$w->element('Textfield', "name$f")->label('County Name:');
$w->constraint('Callback', "name$f")->callback(sub {
my ( $value ) = @_;
return see_if_exists( $value, $c );
});
}
$w->element('Submit', 'Submit')->value('Submit');
$w->element('Reset');
return $w;
}
--
Jason Kohles
email at jasonkohles.com - http://www.jasonkohles.com/
"A witty saying proves nothing." -- Voltaire
More information about the Catalyst
mailing list