views:

385

answers:

1

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" />

+2  A: 

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.

Tim Fountain
I think the only real solution will be to extend Zend\_Form\_Element\_Textarea as you said it... I will accept your solution since I see no other way to do it
Sylvain