[Html-widget] Fieldset not returned by $result->elements if non-Fieldset added first

Carl Franks fireartist at gmail.com
Tue Mar 6 17:56:16 GMT 2007


On 02/03/07, Will Hawes <wdhawes at gmail.com> wrote:
> This was observed using HTML::Widget version 1.10:
>
> $form = HTML::Widget->new();
> $form->element('Hidden','hidden1');
> $form->element('Textfield')->name('textfield1');
> $result = $form->process( $params );
> print scalar $result->elements; # prints "2" ($result->elements
> contains 'hidden1' and 'textfield1')
>
> $form = HTML::Widget->new();
> $form->element('Hidden','hidden1');
> $fieldset = $form->element( 'Fieldset', 'fieldset1' );
> $fieldset->element('Textfield')->name('textfield1');
> $result = $form->process( $params );
> print scalar $result->elements; # prints "1" ($result->elements
> contains only 'hidden1')
>
> It appears that if a HTML::Widget::Element::Fieldset is added to a
> widget after any other element (other than another Fieldset), it is
> not returned by $result->elements.
>
> Adding all non-Fieldset elements to a Fieldset and adding that to the
> main widget, so only Fieldsets are added to the main widget, seems to
> be an effective workaround.

HTML::Widget's handling of fieldsets is somewhat broken; if you search
the mailing list archives, you'll find plenty of discussion about it
last year.
This is one of the reasons I started developing HTML::FormFu instead.

> Is this expected behaviour? If best practice is to wrap all elements
> in Fieldsets, I'd have expected a warning/error of some sort when
> trying to do it differently.

According to the xhtml spec, forms can only contain block-level
elements, which means that inputs must be within a fieldset, or other
block-level item, such as a p or div.

Unfortunately, backwards compatability required that it wasn't
mandatory to add a fieldset first.

Carl



More information about the Html-widget mailing list