0

I'm using HTML::FormHandler and building the form dynamically like so:

my $form = HTML::FormHandler->new(
          name => 'types',
          field_list => [
              parent_id => {
                  type => 'Select',
                  label => 'Parent',
                  required => 1,
                  options => [{value=>'test',label=>'test'}],
              },
          ],
);

Whenever I only pass in one option like above, this is the output that is rendered for the form:

<select name="parent_id" id="parent_id">  
    <option id="parent_id.0" value="test">  </option>  
    <option id="parent_id.1" value="test">  </option>
</select>

However, the resulting output should be:

<select name="parent_id" id="parent_id">  
    <option id="parent_id.0" value="test">test</option>  
</select>

But once I add one more option, such as this:

options => [{value=>'test',label=>'test'},{value=>'test2',label=>'test2'}],

Then the output renders correctly and becomes:

<select name="parent_id" id="parent_id">  
    <option id="parent_id.0" value="test">test</option>  
    <option id="parent_id.1" value="test2">test2</option>
</select>

Is this a bug on HTML::FormHandler's part, or is theres something I'm missing here? Thanks!

srchulo
  • 5,143
  • 4
  • 43
  • 72

1 Answers1

0

Possibly the select type expects a minimum of two options. If you must use the select for a one option selection, and cannot use a checkbox or radio button (if for example the selection list is dynamically generated) could you set the first option to be a default non-value with a 'please select...' label.

doncoyote
  • 168
  • 7