Item8388: Documented method for specifying pre-selected options does not work

pencil
Priority: Normal
Current State: Closed
Released In:
Target Release:
Applies To: Extension
Component: FormPlugin
Branches:
Reported By: Foswiki:Main.DiabJerius
Waiting For:
Last Change By: ArthurClemens
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

 

ItemTemplate edit

Summary Documented method for specifying pre-selected options does not work
ReportedBy Foswiki:Main.DiabJerius
Codebase 1.0.8
SVN Range 4715
AppliesTo Extension
Component FormPlugin
Priority Normal
CurrentState Closed
WaitingFor
Checkins FormPlugin:43f3c46be041 FormPlugin:50ec8a2c142a
ReleasedIn
Topic revision: r4 - 15 May 2010, ArthurClemens
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy