On 9/24/07, Carl Franks <[EMAIL PROTECTED]> wrote: > > > > For a Select with the 'multiple' attribute: > > > > http://www.mountaindragon.com/html/optmselected.htm it is valid to set > > > > 'selected' on many options. How can I do that in FormFu? > > > > > > The logic using default() would need to be fixed to accept an arrayref > > > of values. > > > Patches welcome! > > > > default() already accepts arrayref - it's a simple accessor. Then the > > question is where it is used? I can find it myself - so don't bother > > to dig too deep if you don't have an answer top of your head. > > I think it'll be in Element/_Field.pm in sub _process_value() >
I found it in lib/HTML/FormFu/Element/Select.pm. A simple patch is attached. I can commit it - if you think it is enough. -- Zbyszek
Index: t/multiple_select_fields.t =================================================================== --- t/multiple_select_fields.t (revision 417) +++ t/multiple_select_fields.t (working copy) @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 2; use HTML::FormFu; @@ -25,3 +25,13 @@ EOF is( "$form", $xhtml ); + + +$form = HTML::FormFu->new; + +$form->element('Select')->name('foo')->values( [qw/ one two three /] ) + ->default('two')->multiple(1); +my $select_field = $form->get_element( { name => 'foo' } ); +$select_field->default( [qw/ one three /] ); +is( "$form", $xhtml ); + Index: lib/HTML/FormFu/Element/Select.pm =================================================================== --- lib/HTML/FormFu/Element/Select.pm (revision 417) +++ lib/HTML/FormFu/Element/Select.pm (working copy) @@ -39,10 +39,12 @@ elsif ($submitted) { delete $option->{attributes}{selected}; } - elsif ( defined $default && $default eq $option->{value} ) { + elsif ( defined $default + && (ref $default eq 'ARRAY' + ? grep { $_ eq $option->{value} } @$default + : $default eq $option->{value} ) ) { $option->{attributes}{selected} = 'selected'; } - return; }
_______________________________________________ HTML-FormFu mailing list HTML-FormFu@lists.scsys.co.uk http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu