Skip to content

MultiCheckbox set attributes only on options label #3407

Closed
chrvadala opened this Issue Jan 11, 2013 · 6 comments

6 participants

@chrvadala

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"
        Selection:
    </label>
    <label class="checkbox">
        <input type="checkbox" checked="checked" value="1" name="mySelection[]">
         First Option
    </label>        
</div>

but i want the class only on options value. This is a very common case, because twitter bootstrap require this to work http://twitter.github.com/bootstrap/base-css.html#forms

@radnan
radnan commented Jan 21, 2013

Try this:

$element->setValueOptions(array(
    1 => array(
        'label' => 'First Option',
        'label_attributes' => array('class' => 'checkbox'),
    ),
));
@chrvadala

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');
endforeach;
$element->setValueOptions($values);

but I think that MultiCheckBox need an option like 'label_value_attributes'
e.g.

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

@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).

@gussalazar

I sugget this:

$this->add(array(
'type' => 'MultiCheckbox',
'name' => 'column_show',
'attributes' => array(
'class' => 'style',
),
'options' => array('label'=>'Columnas',
'label_attributes' => array('class' => 'span12','style'=>'margin:0px;'),
'value_options'=> array(
'product_name'=>'x',
'product_name2'=>'y'
),
),
));

@steptom
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 ?

@weierophinney
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.