Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow yii\boostrap\ActiveField to customize the DIV and the LABEL tag around the checkboxList's inputs #5483

Closed
wants to merge 5 commits into from

Conversation

bicf
Copy link

@bicf bicf commented Oct 11, 2014

If inline attribute is false ( https://github.com/yiisoft/yii2/blob/master/extensions/bootstrap/ActiveField.php#97 ) there's no possibility to customize tags around input for the activeField checkboxList.
This patch allows to set the attributes even to DIV and to LABEL.

How to use

Inside itemOptions
add containerOptions to set the DIV attributes
and/or
add labelOptions to set the LABEL attributes

\yii\bootstrap\ActiveForm::checkboxList(
    $check_box_array, [
        'class' => "outside-class",
        'itemOptions' => [
            'containerOptions' => [
                'class' => "div-wrapper-class",
            ],
            'labelOptions'     => [
                'class' => 'label-wrapper-class'
            ],
            'class' => 'input-tag-class',
        ]
    ]);

The effects
From this HTML

<div id="queryform-answermultiple" class="outside-class">
    <div class="checkbox">  // <-----------------------
        <label>   // <-----------------------
            <input type="checkbox" class="input-tag-class" name="QueryForm[answerMultiple][]" value="123">
        </label>
    </div>
    <div class="checkbox">
        <label>
            <input type="checkbox" class="input-tag-class" name="QueryForm[answerMultiple][]" value="456">
        </label>
    </div>
</div>

To this HTML

<div id="queryform-answermultiple" class="outside-class">
    <div class="div-wrapper-class">   // <-----------------------
        <label class="label-wrapper-class" >   // <-----------------------
            <input type="checkbox" class="input-tag-class" name="QueryForm[answerMultiple][]" value="414">
        </label>
    </div>
    <div class="div-wrapper-class">
        <label class="label-wrapper-class">
            <input type="checkbox" class="input-tag-class" name="QueryForm[answerMultiple][]" value="415">
        </label>
    </div>
</div>

@samdark samdark self-assigned this Oct 11, 2014
@bicf
Copy link
Author

bicf commented Oct 11, 2014

@samdark,
I apologize, my fault, drop the commit on composer.json

TIA
Ivan

@samdark samdark removed their assignment Feb 23, 2015
@klimov-paul
Copy link
Member

You can use ActiveField::checkboxTemplate for this use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants