[Catalyst] HTML::Widget, callback constraint, and multiple records per form

Ben Hopkins hopkins.ben at gmail.com
Fri Sep 1 22:14:53 CEST 2006


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 ...




On 9/1/06, Jason Kohles <email at jasonkohles.com> wrote:
>
> On 8/31/06, Ben Hopkins <hopkins.ben at gmail.com> wrote:
> > Here's what I have:  a table (counties) that has county names in it.  I
> want
> > to be able to add counties.  Just one county per screen seems pretty
> dumb,
> > so I want a bunch of counties.  The sole constraint is that a county
> cannot
> > already be in the database, and I figured the Widgets' constraint method
> > would be perfect for that.
> >
> >  Here I make the widget:
> >
> >  sub make_counties_widget {
> >      my ($self, $c) > >
> >      my $w > >
> >      for my $f (1..10) {
> >          $w->element('Textfield', "name$f")->label('County Name:');
> >          $w->constraint('Callback',
> > "name$f")->callback(&see_if_exists);
> >      }
> >
> >      $w->element('Submit', 'Submit')->value('Submit');
> >      $w->element('Reset');
> >      return $w;
> >  }
> >
> >  Already, I'm wondering where the error message will go.  Anyhow, I got
> > completely lost when writing 'see_if_exists' because the args are
> > unintelligible.  It looks like the second arg is the Catalyst context,
> and
> > within there I can find the form results, but if that's the case, why
> does
> > it have to be called once for each field?  It stops being a field
> validation
> > and becomes a form validation called once for each field!?!
> >
> >  Does anybody use callback?  Does anybody do multiple
> create/delete/updates
> > per form?
> >
> You are missing one critical character in your code.  Because you left
> off the backslash before the function call, your callback isn't a
> callback, what is happening is that the function is being run at the
> time you create the widget, and is running 10 times because it's
> inside a loop.  What is actually getting set as the callback is
> whatever &see_if_exists returns.  And because you are calling the
> function with the &, but without parens, it is getting passed the same
> arguments that were passed to make_counties_widget, which is why they
> don't make any sense, and why the context is being passed as a second
> argument.
>
> --
> Jason Kohles
> email at jasonkohles.com - http://www.jasonkohles.com/
> "A witty saying proves nothing."  -- Voltaire
>
> _______________________________________________
> List: Catalyst at lists.rawmode.org
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive:
> http://www.mail-archive.com/catalyst@lists.rawmode.org/
> Dev site: http://dev.catalyst.perl.org/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060901/1b22b1fa/attachment.htm 


More information about the Catalyst mailing list