Subject: | Model::Object cannot cope with array multiple select in HTML::FormHandler::Widget::Field::Select |
When using Model::Object, it appears that the default widget for the
select list cannot cope with an array. This appears to be because the
$optval test within the "find selected" test is assumed to be a scalar,
which is correct for a single select field, but not a multiple one.
This could be fixed in one of (at least) two places:
* HTML::FormHandler::Widget::Field::Select
* HTML::FormHandler::Widget::Field::Role::SelectedOption
As HTML::FormHandler::Widget::Field::Select already has a test for
whether this Select field is multiple, it seems sensible to place the
additional work in this class.
I've fixed this as by augmenting the code with a test for whether
$optval is an arrayref, and adjusting the selected test accordingly.
Here is the patch for the fix I implemented:
diff
HTML-FormHandler-0.35003/lib/HTML/FormHandler/Widget/Field/Select.pm
patched/lib/HTML/FormHandler/Widget/Field/Select.pm
47,48c47,57
< $output .= ' selected="selected"'
< if $self->check_selected_option($option, $optval);
---
Show quoted text
> my $check_selected_option = undef;
> if ('ARRAY' eq ref($optval)) {
> foreach my $multiple_optval (@$optval) {
> $check_selected_option =
$self->check_selected_option($option, $multiple_optval);
Show quoted text> last if ($check_selected_option);
> }
> }
> else {
> $check_selected_option =
$self->check_selected_option($option, $optval);
Show quoted text> }
> $output .= ' selected="selected"' if
($check_selected_option);
(diff -n)
d47 2
a48 11
my $check_selected_option = undef;
if ('ARRAY' eq ref($optval)) {
foreach my $multiple_optval (@$optval) {
$check_selected_option =
$self->check_selected_option($option, $multiple_optval);
last if ($check_selected_option);
}
}
else {
$check_selected_option =
$self->check_selected_option($option, $optval);
}
$output .= ' selected="selected"' if
($check_selected_option);