How to show hide a textbox with label in zend framework?
I have an element in zend form
$item1 = $this->createElement('text','item1');
$item1->setLabel('Enter item 1:')
->setRequired(true)
->setAttr开发者_StackOverflowib('class','hide_textbox');
Here hide_textbox
is a class in a css file which makes display none .
It's hiding text box but not label, i want hide textbox with label,(i don't want to use removeDecorator('label')
)
later i want to show this label and textbox using javascript
Add the class to one of the wrapper decorators.
The specifics of this entirely depend on your decorator scheme. This is also not very easily done using the standard decorators as the label and element are inside different wrappers (<dt>
and <dd>
respectively).
Here's a quick example but it assumes the rest of your form is decorated to not use definition lists...
$item1->setDecorators(array(
'ViewHelper',
'Errors',
'Label',
array('HtmlTag', array('tag' => 'div',
'class' => 'hide_textbox',
'id' => 'item1-wrapper'))
));
Give your form a name which will also become its id:-
$this->setName('formName');
Optionally you can also add a class :-
$this->setAttrib('class', 'formClass');
Then you can target the decorators through css :-
#formName dd, #formName dt{css:rules here;}
or
.formClass dd, .formClass dt{css:rules here;}
I found this by far the easiest way to achieve exactly what you want to do.
精彩评论