Issue Type: Improvement Created: 2009-12-03T02:16:20.000+0000 Last Updated: 2013-01-07T17:40:28.000+0000 Status: Resolved Fix version(s): - 1.12.2 (25/Feb/13)
Reporter: Iszak Bryan (iszak) Assignee: Frank Brückner (frosch) Tags: - Zend_Form
Related issues: Attachments: - ZF-8452.patch
When using Zend_Form_Element_Select in conjunction of setIsArray it is implied that you want a multiple select, when you may not. Now this is definitely a feature for those who want it, but for those who want multiple selects it's a problem.
For example if I use the following code:
<pre class="highlight"> $field = new Zend_Form_Element_Select('field'); $field->setIsArray(true) ->setMultiOptions(array( 'a' => 'A', 'b' => 'B', 'c' => 'C', ));
I get the following output:
<pre class="highlight"> ABC
When I want the desired output:
<pre class="highlight"> ABC
I have looked into work arounds for this problem, but I don't feel they're appropriate for such a simple problem which can easily be corrected by removal of three lines.
Now I propose either we remove the offending code which is on 77 to 79 of Zend_View_Helper_FormSelect which will simply mean people wanting multiple select will be required to add setAttrib('multiple', 'multiple') but will break backwards compatability I believe, or add an option to disable that code.
Posted by Andrew Phillipo (aphillipo) on 2010-07-06T02:54:10.000+0000
Yes, this is extremely strange behaviour; I have been trying to figure out why it is doing this, so thanks for the bug report to know that I'm not going mad. I have no idea how to build a normalselect box in Zend forms, will post here when I figure it out. Seems like creating a normal, simple select box should be simpler, but then that could be said about so much of zend.
Posted by Justin Jahn (4sak3n0ne) on 2010-09-08T13:40:37.000+0000
A ZFForums article describes a temporary fix for this issue.
<pre class="highlight"> <?php $element = new Zend_Form_Element_Select('selectbox', array('multiple' => false )); $element->setIsArray(true);
Posted by Jonathan Steinmann (cmiwebstudio) on 2012-12-26T23:58:37.000+0000
I agree this it a temporary fix, however, there are circumstances where this wouldn't be an option (creating a new instance). One should be able to getElement and add this setIsArray attribute and NOT automatically turn your select into a multi select. This is oversight at best.
Posted by Jonathan Steinmann (cmiwebstudio) on 2012-12-27T00:02:46.000+0000
I should also mention this issue stil exists in Zf 1.12.1 many years after this issue was reported.
Posted by Frank Brückner (frosch) on 2012-12-28T10:04:55.000+0000
I will look into it.
Posted by Jonathan Steinmann (cmiwebstudio) on 2012-12-29T15:10:59.000+0000
Here's the work around:
$element = $this->getElement('element'); $element->setMultiOptions(array('a' => 'A')) ->setIsArray(true) ->setOptions(array('multiple' => false);
Posted by Frank Brückner (frosch) on 2012-12-30T15:08:48.000+0000
@Jonathan Look at the comment from Justin Jahn. ;)
Posted by Frank Brückner (frosch) on 2013-01-05T16:21:49.000+0000
Patch with fix and unit test added. (includes changes from assertType to assertTrue)
Posted by Frank Brückner (frosch) on 2013-01-07T17:40:28.000+0000
Fixed on trunk (25182) and release-1.12 (25183)
Have you found an issue?
See the Overview section for more details.