Re: Quickform ->select -> setSelected
| From: | Bertrand Mansion | Date: | Wed, 03 Jul 2002 13:03:15 +0000 |
| Subject: | Re: Quickform ->select -> setSelected | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-1799@lists.php.net to get a copy of this message | ||
le 3/07/02 13:30, Emiliano Saurin à saurin@tin.it a écrit :
> Hello,
> when i have a string with a comma as an option of the select, the class
> can't set the default selection of a select .
> The function setSelected of the HTML_QuickForm_selec makes:
>
> [originalcode]
> ...
> if (is_string($values)) {
> $values = split("[ ]?,[ ]?", $values);
> $this->_values = $values;
> }
> if (is_array($values)) {
> $this->_values = $values;
> }
> else {
> $this->_values = array($values);
> }
> ...
> [/originalcode]
>
> if $value is a string it becames an array after the split. So the next
> if/else is always true ($this->_values = $values; //is execute twice)
> and the else clause will never process.
> I think this is the problem with the "comma options".
>
> In my case I've resolved it putting an additional check:
> [mycode]
> if ( (is_string($values)) && ($this->getmultiple())) {
> $values = split("[ ]?,[ ]?", $values);
> }
> if (is_array($values)) {
> $this->_values = $values;
> }
> else {
> $this->_values = array($values);
> }
> [/mycode]
>
> Could be a solution or have I missed something?
It looks fine to me. I've fixed this in the CVS.
Thank you,
Bertrand Mansion
Mamasam