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

itemOptions don't apply for yii\boostrap\ActiveField::checkboxList and ::radioList #6527

Closed
Tigrov opened this issue Dec 15, 2014 · 9 comments
Labels
ext:bootstrap status:to be verified Needs to be reproduced and validated.

Comments

@Tigrov
Copy link
Member

Tigrov commented Dec 15, 2014

$options['itemOptions'] is not used for generation inputs.

https://github.com/yiisoft/yii2-bootstrap/blob/master/ActiveField.php#L254
https://github.com/yiisoft/yii2-bootstrap/blob/master/ActiveField.php#L280
#5483

@lynicidn
Copy link
Contributor

all apply: https://github.com/yiisoft/yii2-bootstrap/blob/master/ActiveField.php#L257
u link show if not $options['item']

@Tigrov
Copy link
Member Author

Tigrov commented Dec 15, 2014

I want to add attribute for fields:

$form = yii\bootstrap\ActiveForm::begin();
...
$form->field($model, 'fieldName')->radioList($list, ['itemOptions' => ['data-bind' => 'checked:fieldName']])

I expect:

...
<input type="radio" name="fieldName" value="1" checked="" data-bind="checked:fieldName">
...

But getting:

...
<input type="radio" name="fieldName" value="1" checked="">
...

@lynicidn
Copy link
Contributor

yes, it bugged behavior in bootstrap, but u must use

$form->field($model, 'fieldName')->radioList($list, ['item' => function() {
return  '<div class="checkbox">' . Html::checkbox($name, $checked, ['label' => $label, 'value' => $value, 'data-bind' => 'checked:fieldName']) . '</div>';
}]);

@Tigrov
Copy link
Member Author

Tigrov commented Dec 15, 2014

But if I use yii\widgets\ActiveForm it works

$form = yii\widgets\ActiveForm::begin();

@Tigrov
Copy link
Member Author

Tigrov commented Dec 15, 2014

Maybe worth to correct the code?

}  elseif (!isset($options['item'])) {
    $itemOptions = isset($options['itemOptions']) ? $options['itemOptions'] : [];
    $options['item'] = function ($index, $label, $name, $checked, $value) use ($itemOptions) {
        return '<div class="radio">' . Html::radio($name, $checked, array_merge($itemOptions, ['label' => $label, 'value' => $value])) . '</div>';
    };
}

@samdark samdark added the status:to be verified Needs to be reproduced and validated. label Dec 15, 2014
@samdark samdark added this to the 2.0.2 milestone Dec 15, 2014
@cebe cebe modified the milestones: 2.0.x, 2.0.2 Jan 10, 2015
@MrEhbr
Copy link

MrEhbr commented Jul 31, 2015

Checked on 2.0.5 still doesn't work, but it works with $form = yii\widgets\ActiveForm::begin();

@makroxyz
Copy link
Contributor

makroxyz commented Sep 9, 2015

+1

@cronfy
Copy link
Contributor

cronfy commented Sep 29, 2015

This is because yii\bootstrap\ActiveField uses custom formatter by overriding 'item' option: https://github.com/yiisoft/yii2-bootstrap/blob/master/ActiveField.php#L269 (look near !isset($options['item']).

Implementation contradicts the documentation, where is said:

Options (name => config) for the radio button list. For the list of available options please refer to the $options parameter of yii\helpers\Html::activeRadioList().

Indeed, options of yii\helpers\Html::activeRadioList() can not be used for rendering yii\bootstrap\ActiveField::radioList().

Either documentation, or bootstrap radioList() implementation should be fixed.

@yii-bot
Copy link

yii-bot commented Jan 24, 2016

Issue moved to yiisoft/yii2-bootstrap#106

@yii-bot yii-bot closed this as completed Jan 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext:bootstrap status:to be verified Needs to be reproduced and validated.
Projects
None yet
Development

No branches or pull requests

8 participants