[html-formfu] Different attributes for the first record in a repeatable block

Carl Franks fireartist at gmail.com
Wed Apr 1 08:48:49 BST 2009


2009/3/31 Ascii King <tech at swattermatter.com>:
> That works great! Thank you.  How do I count the number of elements returned
> by the get_all_element function?
>
> $form->get_all_element({ type => Repeatable })
>
> If I display the variable, I can see that I get four elements, but I don't
> know how to count them with code.

"get_all_element" will only return the 1st item that would otherwise
be returned by "get_all_elements".
The "all" just means it works recursively.

So in your case, "get_all_element" should be returning a Block, which
itself contains some number of elements.

It's not very pretty - you have to dereference the array-ref to a
list, then count it in scalar context:

    $count = scalar @{ $form->get_all_elements({ type =>
Repeatable})->get_elements };

Hope that helps,
Carl



More information about the HTML-FormFu mailing list