[html-formfu] Question about grabbing info from Repeatable element

Mario Minati mario.minati at googlemail.com
Sun Jul 26 20:33:33 GMT 2009


Shawn Moughtin schrieb:
> I am using a bit of javascript code to add more rows for a 
> repeatable.  However, this requires the outer div tag created by the 
> repeatable to have an id that matches the full nested name. For 
> example, outer_2.inner_3.fieldname If I use the nested_name option, I 
> only get inner_3
>
> I had some code that was working for awhile, but it had to be changed 
> to reflect the new naming process. I can see no way to set this info 
> in the .yml file, so I am doing it in perl. I use the following code, 
> but it fails because of my incredibly poor understanding of this 
> programming language. My plan is to grab the ID of the first INPUT 
> element in the repeatable DIV tag and then use regex to take what I 
> need from it. If there is an easeir way, I would love to hear it.
>
> sub show_repeatables {
>    my ($form, $c) = @_;
>
>    # Grab every repeatable and all of it's elements
>    my $Repeat_List = $form->get_all_elements({ type => 'Repeatable'});
>
>    # Grab the first repeatable and the first element in it (div tag)
>    my $Repeat_field = $Repeat_List->[0]->get_element();
>
>    # Grab the first element in the div tag (input text)
>    $Repeat_field = $Repeat_field->get_element();
>
>    # Grab the ID attribute from the selected element.
>    my $Repeat_id = $Repeat_field->attributes->{'id'};
>
> }
>
> Results:
> $Repeat_field = <div class="text">
> <input id="outer_1.inner_1.fieldname" type="text" 
> name="outer_1.inner_1.fieldname"/>
> </div>
>
> $Repeat_id = NULL
>
> This code is supposed to put "outer_1.inner_1.fieldname" into 
> $Repeat_id.  It fails when run as presented, but, if I remove the 
> following line:
>
>    # Grab the first element in the div tag (input text)
>    $Repeat_field = $Repeat_field->get_element();
>
> It then correctly returns:
> - $Repeat_field = (the entire first repeatable element)
> - $Repeat_id = (ID assigned in .yml file)
>
> How do I grab the full nested name or id? Why doesn't this code work 
> to grab the id from the selected element?
Hi Shawn,

sorry but I don't understand yet where your problem lifes. On the 
javscript side or on the perl side. Usually formfu will do all the 
backend processing for you and you don't have to play with nested_names 
and so on.
You can add more fields with javascript and just adjust the count field 
and it will work.
Maybe you forgot to the set new_rows_max modelconfig value of the 
repeatable block to an appropriate value, otherwise the DBIC model will 
not add the new rows.

Greets,

Mario



More information about the HTML-FormFu mailing list