Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Sets specific attributes (as class,title...) to "Zend\Form\Select" options #3792

Merged
merged 1 commit into from

3 participants

@neilime

Exemple :

$element = new SelectElement('foo');
$options = array(
    array(
        'label' => 'This is the label',
        'value' => 'value',
        'attributes' => array(
            'class' => 'test-class'
        ),
    ),
);
$element->setValueOptions($options);
@mwillbanks
Collaborator

Would this also apply to radio and multicheckbox?

@neilime

"Zend\Form\View\Helper\FormMultiCheckbox" already supports "attributes" option spec

@weierophinney weierophinney merged commit ec7687b into from
@neilime neilime deleted the branch
@ghost Unknown referenced this pull request from a commit
@weierophinney weierophinney Merge branch 'hotfix/3792' into develop
Close #3792
de793ba
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 library/Zend/Form/View/Helper/FormSelect.php
@@ -160,6 +160,11 @@ public function renderOptions(array $options, array $selectedOptions = array())
}
$attributes = compact('value', 'selected', 'disabled');
+
+ if (isset($optionSpec['attributes']) && is_array($optionSpec['attributes'])) {
+ $attributes = array_merge($attributes, $optionSpec['attributes']);
+ }
+
$this->validTagAttributes = $this->validOptionAttributes;
$optionStrings[] = sprintf(
$template,
View
6 tests/ZendTest/Form/View/Helper/FormSelectTest.php
@@ -37,6 +37,9 @@ public function getElement()
array(
'label' => 'This is the third label',
'value' => 'value3',
+ 'attributes' => array(
+ 'class' => 'test-class',
+ ),
),
);
$element->setValueOptions($options);
@@ -58,6 +61,9 @@ public function testCreatesSelectWithOptionsFromAttribute()
$this->assertContains('value="value1"', $markup);
$this->assertContains('value="value2"', $markup);
$this->assertContains('value="value3"', $markup);
+
+ //Test class attribute on third option
+ $this->assertRegexp('#option .*?value="value3" class="test-class"#', $markup);
}
public function testCanMarkSingleOptionAsSelected()
Something went wrong with that request. Please try again.