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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -