Skip to content

MultiCheckbox set attributes only on options label #3407

chrvadala opened this Issue Jan 11, 2013 · 6 comments

6 participants


Is there a method to specific attributes only on options label in MultiCheckbox element?

if i do $element->setLabelAttributes(array('class'=>'checkbox')); each label will have class="checkbox"

<div class="control-group ">
    <label for="mySelection" class="checkbox">   <---- here i don't want class="checkbox"
    <label class="checkbox">
        <input type="checkbox" checked="checked" value="1" name="mySelection[]">
         First Option

but i want the class only on options value. This is a very common case, because twitter bootstrap require this to work

radnan commented Jan 21, 2013

Try this:

    1 => array(
        'label' => 'First Option',
        'label_attributes' => array('class' => 'checkbox'),

This works, but it isn't a good solution... Few days ago I wrote this code

$values = $element->getValueOptions();
foreach($values as &$val):
    $val['label_attributes'] = array('class' => 'checkbox');

but I think that MultiCheckBox need an option like 'label_value_attributes'

$element->setOption('label_value_attributes', array('class'=>'checkbox'));

@ArtigianoDelWeb just to clarify, is the issue that MultiCheckbox/Radio causes an inconsistency when used with the FormLabel helper? The FormLabel assumes it should also use the label_attributes.

I like what you suggest about having a 'label_value_attributes' to solve the inconsistency. The trick would be to do so without causing a BC break (which at quick glance looks doable).


I sugget this:

'type' => 'MultiCheckbox',
'name' => 'column_show',
'attributes' => array(
'class' => 'style',
'options' => array('label'=>'Columnas',
'label_attributes' => array('class' => 'span12','style'=>'margin:0px;'),
'value_options'=> array(

steptom commented Aug 5, 2013

A solution could be to implement a setLabelAttributesOption(array $labelAttributes) method to the Zend\Form\Element\MultiCheckbox class.
This method play the code that @work-out-web has describe above...
Is it a good idea ?

Zend Framework member

There's "I don't like it," and then there's "broken." Based on the reports in this issue, I'd argue we're in the first camp, and thus I'm closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.