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

Shawn Moughtin tech at swattermatter.com
Fri Jul 24 14:05:19 GMT 2009


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?



More information about the HTML-FormFu mailing list