Permalink
Browse files

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

  • Loading branch information...
neilime committed Feb 15, 2013
1 parent f825368 commit ec7687bae66ab0cc378036ac3b7bfad4d76f111f
@@ -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,
@@ -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()

0 comments on commit ec7687b

Please sign in to comment.