How would I format Zend_Form_Element_Radio so the label follows the input?

前端 未结 6 954
猫巷女王i
猫巷女王i 2021-01-05 20:41

The default decorator for the Zend_Form_Element_Radio is

6条回答
  •  渐次进展
    2021-01-05 20:57

    Probably my best idea so far, is to change the ZF [Zend Framework] HTML code from within jQuery, so that it gets compatible with jQuery UI format.

    Here is the solution:

    in ZF Form construction:

    $this->setElementDecorators(array(
                                    'ViewHelper',
                                    'Errors',
                                    array(array('rowElement'=>'HtmlTag'), array('tag'=>'div', 'class'=>'element')),
                                    array('Label', array('class'=>'first')),
            ));
    

    The important thing here is the div with class=element that will wrap all inputs [so that it is easy to get to them in jQuery]

    And here is the JS code:

    $(function() {
        $( "div.element > label" ).each(function() {
            $('input', this).after('');
            $('label', this).text($(this).text());
            var input = $('input', this).detach();
            var label = $('label', this).detach();
    
            var parent = $(this).parent();
            $(this).remove(); 
            input.appendTo(parent);
            label.appendTo(parent);
        });
        $( "div.element" ).buttonset();
    });
    

提交回复
热议问题