I need to make the following html using Zend form and form decorators...
<ul>
<li id="containeruser1">
<label for="user1"><input type="checkbox" class="textbox" value="1" id="user1" name="users[]">User One</label>
</li>
<li id="containeruser2">
<label for="user2"><input type="checkbox" class="textbox" value="2" id="user2" name="users[]">User Two</label>
</li>
<li id="containeruser3">
<label for="user3"><input type="checkbox" class="textbox" value="3" id="user3" name="users[]">User Three</label>
</li>
<li id="containeruser4">
<label for="user4"&开发者_JAVA技巧gt;<input type="checkbox" class="textbox" value="4" id="user4" name="users[]">User Four</label>
</li>
</ul>
The php code i use is ....
$userelement = new Zend_Form_Element_MultiCheckbox ( 'users' );
$userelement-> setRequired(true)
->addDecorator("<li>")
->addMultiOptions ( array ('1' => 'User One', '2' => 'User Two', '3' => 'User Three', '4' => 'User Four' ) )
->setSeparator ( '</li><li>' )->addValidator('NotEmpty', true)
->addErrorMessage('Please select at
least one user');
$userelement->class = 'textbox';
The output is not exactly wht i want.... Each li tag needs to have a unique id so tht i can use some js to do some client side validations and modifications...... Im beginning to use Zend_form and the decorators are a bit confusing ......Please do help...
I have custom ViewScripts for each element type, giving me plenty of styling and scripting hooks. Here are my posts on that:
- ViewScripts for File Elements
- Recommended Path For Zend Form Element View Scripts
- Override Separator on Zend_Form Radio Elements When Using a ViewScript Decorator
Consider using JS to locate the container. This way you don't have to change the decorators.
jQuery example
// example 1
$('#user1').parent().parent().css('color', 'green');
// example 2
$('#user1').parents('li').css('color', 'green');
I have extended Zend_Form_Element_MultiCheckbox and made a new element instead of using element decorators .... Thanks for all your help...
精彩评论