[Html-widget] Seemingly incorrect fieldset behavior

Michael Gray mjg17 at eng.cam.ac.uk
Tue Oct 3 12:41:30 CEST 2006


On Oct 2 2006, Michael Alan Dorman wrote:

>Hi, all.
>
>I have the following script:
>
>   #!/usr/bin/perl
>
>   use strict;
>   use warnings;
>   use HTML::Widget;
>
>   my $widget = HTML::Widget->new ('widget')->legend ('Widget');
>   $widget->element (Textfield => 'a')->label ('A');
>   my $fieldset = $widget->element (Fieldset => 'fieldset');
>   $fieldset->legend ('Fieldset');
>   $fieldset->element (Textfield => 'b')->label ('B');
>   $widget->element (Textfield => 'c')->label ('C');
>   my $result = $widget->process;
>   print $result;
>
> ...
>I don't understand why the fieldset containing textfield B has been 
>relocated to be after the top-level fieldset?  I checked the HTML 
>standard, and nested fieldsets certainly seem to be legal there, so 
>there would seem to be no need for this behavior in order to satisfy 
>some external requirement---so is this a bug or a feature?

It's a feature - or possibly a bug, but one that can be avoided by 
following the now-recommended usage. When you add the first Textfield, H::W 
generates an implicit fieldset and puts the Textfield in it. When you add a 
fieldset to the widget, it appends it after the implicit fieldset.

What is recommended is that you add your own top-level fieldset explicitly, 
and add your Textfield and nested fieldset to that:

  my $widget = HTML::Widget->new ('widget')->legend ('Widget');
  my $main_fs = $widget->element (Fieldset => 'main_fs');
  $main_fs->element (Textfield => 'a')->label ('A');
  my $fieldset = $main_fs->element (Fieldset => 'fieldset');
  $fieldset->legend ('Fieldset');
  $fieldset->element (Textfield => 'b')->label ('B');
  $main_fs->element (Textfield => 'c')->label ('C');
  my $result = $widget->process;
  print $result;

Should do what you are expecting.

-- 
Michael



More information about the Html-widget mailing list