Item8388: Documented method for specifying pre-selected options does not work
Priority: Normal
Current State: Closed
Released In:
Target Release:
Applies To: Extension
Component: FormPlugin
Branches:
The documentation for the
value
attribute implies it should be used for specifying preselected items in a
selectmulti
input field
For multi-select elements: the selected items; a comma delimited string.
Unfortunately, that doesn't work. Here's what I think should work:
%STARTFORM{ name="f1" action="save" }%
%FORMELEMENT{ type="selectmulti" name="s1" value="c" size="3..10" options="a, b, c" }%
%ENDFORM%
but the output HTML form doesn't have the option "c" selected.
The relevant code in
FormPlugin.pm is this:
1075 my $selectedoptions = $params->{'default'} || undef;
1076 my $isMultiple = $MULTIPLE_TYPES{$type};
1077 if ($isMultiple) {
1078 my @values = param($name);
1079 $selectedoptions ||= join( ",", @values );
1080 }
1081 else {
1082 $selectedoptions ||= param($name);
1083 }
A few notes:
- The initial value for
$selectedoptions
is taken from an undocumented parameter, default
.
- Subsequent values are extracted from the CGI parameter given by
$name
, a behavior which is also undocumented.
- This is the only place in the code that
param
is called as a function (using the default CGI object) rather than as $query->param
. I'm guessing that this is a bug.
- This is the only value that seems to be pulled from the CGI parameters. That's definitely odd.
- I can't find any code which uses the
value
attribute to set $selectedoptions
I'd offer a patch, but the code has enough undocumented behavior that I'm not sure what's supposed to really happen.
--
DiabJerius - 15 Jan 2010
You are right, this should be
$params->{'value'}
, so:
my @values = $params->{'value'}
.
--
ArthurClemens - 15 May 2010