[html-formfu] Re: Adding a link to the output of a nested repeatable

Mike South msouth at gmail.com
Tue Jun 2 22:07:02 GMT 2009


On Tue, Jun 2, 2009 at 10:54 AM, Mike South <msouth at gmail.com> wrote:
> Hi,
>
> I have a form with a repeatable element (using
> HTML::FormFu::Model::DBIC) representing an interviewee that lets me
> edit the interviewee's firstname and lastname columns.  I also want a
> link to appear next to each one that lets you edit the rest of the
> details for an interviewee (like href="/interviewee/edit/[id]" ).
> What is the best way to generate that link?
>
> I was guessing plugin.  My thought was that I could attach the plugin
> to the Hidden field that gets the id.  Within the plugin, I would look
> at the id field, create the link, and add the link to the end of the
> HTML that generates the hidden form field.  (Kludgy, but I just wanted
> to get something working).  I don't even know if I can do that from a
> plugin, but here's what I tried so far:
>
> Using the code from StashValid, I tried to put a warning with the
> value of the field.  However, 'valid' never returned true and the
> param was always undefined (whether I asked for valid() or not).
>
> Here is the plugin:
>
> package HTML::FormFu::Plugin::Mike;
> use strict;
> use base 'HTML::FormFu::Plugin';
>
> sub post_process {
>
>    my ($self) = @_;
>
>    my $form = $self->form;
>    my $name = $self->parent->nested_name;
>    warn "name is [$name]";
>
>    if ( $form->valid($name) ) {
>        warn "val is ".  $form->param($name);
>    }
>    else {
>        warn "not valid!";
>    }
> }
> 1;
>
> Here is how I attached it to the field
>               elements:
>                  - type: Hidden
>                    name: interviewee_id
>                    plugins:
>                      - Mike
>
> The field is getting written out correctly with a value, like this:
>
> <input name="interviewees_1.interviewee_id" type="hidden" value="4" />
>
> The 'name' gets warned out correctly:
>
> name is [interviewees_1.interviewee_id]
>
> but it's followed by
>
> not valid!
>
> (or, if I take out the condition, an uninitialized value warning).
>
> I don't really know what to try next.
>
> Thanks in advance for any help anyone can give.
>
> mike
>

I realize now (now that the implications of Carl's recent posted
plugin example have had a chance to cook in the ol' subconscious) that
a $self->parent->value call gives me the value of the data.  I think I
saw something that adds an element after a given element, so I'll see
if I can make a src element in my plugin using that data and add it in
there.  (Up to now my use of FormFu has been about 95%
configuration-only, which I think is a great testament to how much
"just works").

Anyway, just wanted to let everyone know I think I've found my way on this.

mike



More information about the HTML-FormFu mailing list