Reputation: 1558
Is it possible to alter an html attribute of a Zend_Form_Element in a Decorator previously added ?
Lets say I have a decorator named RichTextArea. When I add it to a Zend_Form_Element_Textarea, I want the decorator to add the class "rich" to the textarea.
The final output should look like this :
<textarea name="content" id="content" class="rich" />
Upvotes: 0
Views: 1582
Reputation: 8728
It's possible to add any HTML-Attribute with
// @var Zend_Form_Element $element
$element->setAttribute($key, $value);
But you also can access the Attributes as a property like
$element->key = $value;
For more Information read this Section in Zend-Documentation: http://framework.zend.com/manual/1.12/en/zend.form.elements.html#zend.form.elements.metadata
Upvotes: 1
Reputation: 33148
It is possible, but the syntax depends a little on how you are building the form. Easiest way is to do it on the element itself as you add it:
$element = new Zend_Form_Element_Text('something');
$element->class = 'rich';
$form->addElement($element);
or if you mass-assigned the decorators, e.g.:
$element = new Zend_Form_Element_Text('something');
$element->setDecorators(array(
'Errors',
'Label',
array(array('row' => 'HtmlTag'), array('tag' => 'div'))
));
[...]
$decorator = $element->getDecorator('row');
$decorator->setOption('class', 'rich');
If you are using a rich text editor like TinyMCE or similar, another option might be to create a custom form element that extends Zend_Form_Element_Textarea and always add your class to it.
Upvotes: 4