ZF-4879: Multiple equal option values to Zend Form Select elements

Issue Type: Improvement Created: 2008-11-08T11:01:18.000+0000 Last Updated: 2012-04-27T15:45:11.000+0000 Status: Open Fix version(s): Reporter: Bernd Matzner (bmatzner) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Form

Related issues: Attachments:


Currently, it's not possible to use addMultiOptions to pass an array with equal option values to a Select/MultiSelect form element, because the value has to be stored as the key of the multiOptions array.

in a similar manner to the addMultiOptions option of specifically setting key and value, formSelect should be enhanced to support an array of key/value pairs.

Because I needed a solution now, I created my own ViewHelper to take into account for the same value in different optgroups, like this:

<pre class="highlight">
                    $list[] = $this->_build($val, $lab, $value, $disable);

is replaced by

<pre class="highlight">
                    if (is_array($lab) 
                        && array_key_exists('key', $lab)
                        && array_key_exists('value', $lab)
                    ) { 
                        $list[] = $this->_build($lab['key'], $lab['value'], $value, $disable);
                    } else {
                        $list[] = $this->_build($val, $lab, $value, $disable);

which requires to prepare the array passed to the viewhelper like ````


Posted by Gerhard Eriksson (drone82) on 2011-07-12T08:46:59.000+0000

My project is hanging on this, and programming around it is a pain for me.

Posted by Gerhard Eriksson (drone82) on 2011-07-12T11:34:51.000+0000

And I can't use this solution because I don't use opt grouping. But I must have this solution applied so I can use same value with different labels. So the users selects right foreign key-number in a database relation with a barcode scan. Why I have this problem is that HP's product number vary up to 3 times on same product, and all labelscans must match to that 1 product.

Posted by Linus R (silverquick) on 2012-04-27T15:45:11.000+0000

What about changing how Zend_Form_Element_Multi stores options? Instead of storing them as one array, it can store the keys as one array and the labels as a separate array. It could also have an $_allowDuplicateKeys option, perhaps defaulting to false for backwards-compat.

Then Zend_View_Helper_FormSelect::formSelect() would also have to be refactored slightly, but it's not as straightforward if one wants to avoid changing the method signature. The $options param can't simply be an array($arrayOfKeys, $arrayOfLabels), because currently if an $options element is itself an array, it triggers the ing. Of course one could just add another param on the end, array $optionLabels = null, and if it's set, $options is interpreted as just the keys, but then it's weird that $listsep is between them. I'll try to think more about this...

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.