[html-formfu] option attributes
Carl Franks
fireartist at gmail.com
Wed Feb 4 15:27:20 GMT 2009
2009/2/4 Dermot <paikkos at googlemail.com>:
> 2009/2/4 Carl Franks <fireartist at gmail.com>:
>> 2009/2/4 Dermot <paikkos at googlemail.com>:
>>> Hi,
>>>
>>> Is it possible to set the 'selected' attribute on a option element?
>>> I have tried selected => 1 and selected => 'selected' but nether give
>>> me the effect.
>>
>> Like any other field, you just need to call:
>> $field->default( $value )
>>
>> where $value == the selected option's value, not it's label.
>>
>> To select multiple options, you need to set $field->multiple(1)
>>
>> type: Select
>> name: foo
>> multiple: 1
>
> understood.
>
>
>> and give default() an arrayref of values.
>> $field->default([ 1, 2, 3, 4 ]);
>
> Thanx that's worked.
>
> Am I mistaken or is the rendered XHTML the same?
I wouldn't recommend setting attributes->{selected} via options().
There's code that makes sure the correct options are selected,
depending on the values of submitted(), render_default(), and probably
other variables.
$field->default() should always "do the right thing" :)
Cheers,
Carl
More information about the HTML-FormFu
mailing list