2009/2/4 Dermot <paik...@googlemail.com>: > 2009/2/4 Carl Franks <fireart...@gmail.com>: >> 2009/2/4 Dermot <paik...@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 _______________________________________________ HTML-FormFu mailing list HTML-FormFu@lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu