[Html-widget] Template error with 1 element HW

Carl Franks fireartist at gmail.com
Fri Sep 29 15:05:24 CEST 2006


On 22/09/06, Brian Kirkbride <brian.kirkbride at deeperbydesign.com> wrote:
> A. Pagaltzis wrote:
> > * Brian Kirkbride <brian.kirkbride at deeperbydesign.com> [2006-09-22 22:15]:
> >> elements = form.elements.size == 1 ? [ form.elements ] : form.elements;
> >> FOREACH element = elements;
> >
> >     FOREACH element = form.elements.list
> >
> > ?
> >
> > Regards,
>
> That was my first thought.  I've found a workaround, but here's what is
> happening and why.
>
> form.elements returns a @list not a @$listref
> TT promotes the single hashref returned (the container object) into a list
> As a result the hashref is not treated by TT as a scalar
> Checks for .size and using .list to turn it into a single-value-list fail
>
> This didn't happen in TT-2.14 but is happening with TT-2.15, causing my
> previously mentioned ugly workaround of .size==0 to fail.
>
> I fixed it for now with this:
>
> IF form.elements.keys;
>    form.elements.field_xml;
>    form.elements.error_xml;
> ELSE;
>    FOREACH element = form.elements;
>      element.field_xml;
>      element.error_xml;
>    END;
> END;
>
> Perhaps we need a method in H::W::Results that returns [ $self->get_elements ]?
>
> sub get_elements_ref {
>    return [ shift->get_elements ];
> }

Ok,
$widget now has
get_elements_ref()
get_filters_ref()
get_constraints_ref()

$result now has
elements_ref()

Available now in svn, or when v1.10 is released.

Carl



More information about the Html-widget mailing list