zend框架-从zend_Form_Element_Radio中删除默认的装饰器标签


zend framework - remove default decorator label from the Zend_Form_Element_Radio

在我的zend表单中,创建单选按钮后有标签包装单选按钮

<label for="type-per"><input type="radio" class="radio" value="per" id="type-per" name="type">Percentage</label>

我遇到的问题是,当我单击包装标签时,而不是在按钮上,按钮被选中,所以我想删除包装标签,我不想删除表单中的所有标签。我只想去掉单选按钮的包装标签。这是我的无线电按钮代码,

    $type = new Zend_Form_Element_Radio('type');
    $type->setLabel('Type');
    $type->addMultiOption('per', 'Percentage');
    $type->addMultiOption('fix','Fixed');
    $type->setRequired(true);
    $type->removeDecorator('Errors');
    $type->addErrorMessage('You must select a type.');
    $type->class = 'radio';
    $type->setDecorators(
                         array(
                            array('ViewHelper',
                                        array('helper' => 'formRadio')
                            ),
                            array('Label',
                                        array('class' => 'label')
                            ),
                            array(
                                array('out'=>'HtmlTag'),
                                array('tag' => 'div', 'class' => 'formfield', 'id' => 'type_div')
                             ),
                             array(
                                array('prepend' => 'HtmlTag'),
                                array('tag' => 'div', 'class' => 'clear', 'placement' => 'prepend')
                             )                                                                                               
                         )                           
                      );

请帮助:(

首先,您的装饰器集不会生成您提供的HTML。然而

要完全删除标签,只需从装饰器集合中删除此行

array('Label', array('class' => 'label') ),

但它会删除文本太

你也可以试试

array('Label', 
      array('class' => 'label',
           'placement'=>'APPEND',
           'tag'=>'span', //if you want to use other tag
           'disableFor'=>true) 
     ),

可能'disableFor'=>true就是您所需要的,因为它删除了labelfor属性,该属性负责在单击label时激活input

第三种方法是使用一个只附加文本的自定义装饰器(您可以使用Label装饰器作为base,并用您的代码替换355. $label = $view->formLabel($element->getFullyQualifiedName(), trim($label), $options);

附带说明:您也不需要$type->removeDecorator('Errors');,因为当您稍后使用setDecorators时,它将首先删除所有装饰器(包括Errors),然后添加您列出的新装饰器,如果您省略'Errors',则不会添加它。