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 PROTECTED] > wrote:
On 8/31/06, Ben Hopkins <[EMAIL PROTECTED]> 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 = $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(&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 PROTECTED] - http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire

_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/

Reply via email to