开发者

Zend Decorators with radio buttons?

开发者 https://www.devze.com 2023-03-24 11:04 出处:网络
How do I turn the standard dt and dd tags provi开发者_JAVA技巧ded by default with Zend to using ul and li for a radio button list?

How do I turn the standard dt and dd tags provi开发者_JAVA技巧ded by default with Zend to using ul and li for a radio button list?

so that the end results is:

ul tag

li tag radio button 1 end li tag

li tag radio button 2 end li tag

li tag radio button 3 end li tag

end ul tag

instead of dl dt tags.

thanks.


You'll need to specify a custom sequence of decorators for your radio button element, like so:

$this->addElement('radio', 'zipZangZowie', array(
    'decorators' => array(
        'ViewHelper',
        array(array('AddTheLi' => 'HtmlTag'), array('tag' => 'li')),
        array(array('AddTheUl' => 'HtmlTag'), array('tag' => 'ul')),
        'Errors',
        array('Description', array('tag' => 'p', 'class' => 'description')),

        // specifying the "div" tag to wrap your <label> elements is not strictly 
        // necessary, but it produces valid XHTML if your form elements are wrapped
        //  in block-level tags like "<li>" (see next comment)
        array('Label', array('tag' => 'div')),

        // uncomment the following if all of your form elements are wrapped in "<li>"
        //array('HtmlTag', array('tag' => 'li')),
    ),
    'disableLoadDefaultDecorators' => true,
    'label' => 'Zip Zang Zowie',
    'separator' => '</li><li>',
    'attribs' => array(
        'options' => array(
            'foo' => 'Option 1', 
            'bar' => 'Option 2', 
            'baz' => 'Option 3'
        ),
    ),
));

I wish decorating Zend forms wasn't so complicated. Anyway, the decorators array above is based on Zend's default decorators. You may have to customize them more to your liking. The key parts that make the individual radio buttons wrapped in a list are the separator attribute, which tells ZF what to place in between each radio button segment, and the two extra HtmlTag wrappers for wrapping this block in the outer <ul><li>...</li></ul> tags.

0

精彩评论

暂无评论...
验证码 换一张
取 消