php - Using radioList method with ActiveField in Yii2 to provide different options per radio box -
i'm using radiolist method within activefield widget , i'm trying work out how set different options different radio boxes within same list.
i have this...
$form->field($model, 'some_question')->inline()->radiolist( [ 1 => yii::t('general', 'yes'), 0 => yii::t('general', 'no') ], ['itemoptions' => ['value' => 1, 'data-foo' => 'bar']] )->label(false);
but whatever set in itemoptions
gets set on all radio buttons - there way set different values each one?
use callable item
this.
$form->field($model, 'some_question')->inline()->radiolist( [ 1 => yii::t('general', 'yes'), 0 => yii::t('general', 'no') ], ['item' => function ($index, $label, $name, $checked, $value) { switch ($value) { // different options per value case 1: $options = [ 'data-foo' => 'bar' ]; break; case 0: $options = [ 'data-next' => 'smthng' ]; } return \yii\bootstrap\html::radio($name, $checked, array_merge($options, [ 'value' => $value, 'label' => \yii\bootstrap\html::encode($label), ])); }] )->label(false);
Comments
Post a Comment