remove default decorator label from the Zend_Form_Element_Radio
in my zend form after creating a radio button there is label wrapping radio button
<label for="type-per"><input type="radio" class="radio" value="per" id="type-per" name="type">Percentage</label>
the problem i having is , when i click the wrapping label , not on the button the button is selected , so i want to remove the wrapping label , i don't want to remove all labels in my form . i only want to remove the radio button's wrapping label . this is my radio buttons code ,
$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')
)
)
);
please help :(
First of all your set of decorators do not generate the HTML you provided. However
To completely remove the label just remove this line from your set of decorators
array('Label', array('class' => 'label') ),
but it will remove the text too
you could also try
array('Label',
array('class' => 'label',
'placement'=>'APPEND',
'tag'=>'span', //if you want to use other tag
'disableFor'=>true)
),
probably 'disableFor'=>true
is what you need, because it removes the for
attribute of the label
which is responsible for activating the input
when clicked on the label
.
Third way is to use a custom decorator that only appends text (you can use Label decorator for base and replace 355. $label = $view->formLabel($element->getFullyQualifiedName(), trim($label), $options);
with your code)
As a side note: You also do not need $type->removeDecorator('Errors');
because when you use setDecorators
later it will first remove all decorators (including Errors
) then add the new ones you listed, and if you omit 'Errors'
it will not be added.
精彩评论