Re: [QuickForms] replacing options in select?
| From: | Bertrand Mansion | Date: | Tue, 18 Mar 2003 16:53:18 +0000 |
| Subject: | Re: [QuickForms] replacing options in select? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-4291@lists.php.net to get a copy of this message | ||
<ghopson@mac.com> wrote :
> Hi,
>
> I want to reduce the base set of options in a select widget. Is there
> any API to do this, or a clever combination of get_element on the form
> or something?
>
> To get round my problem I have overloaded loadArray on select.php as
> follows:
>
> function loadArray($arr, $values=null)
> {
> if (!is_array($arr)) {
> return PEAR::raiseError('Argument 1 of HTML_Select::loadArray is not
> a valid array');
> }
> if (isset($values)) {
> $this->setSelected($values);
> }
> $this->_options = array(); // <-- Added line to zap array
> foreach ($arr as $key => $val) {
> // Warning: new API since release 2.3
> $this->addOption($val, $key);
> }
> return true;
> } // end func loadArray
>
> Does this make sense, or is there a better way?
Why don't you change the options array first ?
Bertrand Mansion
Mamasam