jquery - yii2 kartik switch input type radio button get value in javascript -
i use yii2 kartik switch input type radio , want value of selected option in javascript (specially in jsexpression), here code :
$model->orientation = 'portrait'; echo $form->field($model, 'orientation')->widget(switchinput::classname(), [ 'name' => 'information_orientation', 'type' => switchinput::radio, 'value' => 'portrait', 'items' => [ ['label' => 'portrait   ', 'value' => 'portrait'], ['label' => 'paysage   ', 'value' => 'paysage'], ], 'pluginoptions' => [ 'ontext' => 'oui', 'offtext' => 'non', 'oncolor' => 'success', 'offcolor' => 'danger', 'size' => 'mini' ], 'labeloptions' => ['style' => 'font-size: 13px'], ]);
i have tried :
$([name='information-orientation']).val()
but returned undifined value
switchinput
class does not care name property give it
according docs, need wrap name
in options
array
echo $form->field($model, 'orientation') ->widget(switchinput::classname(), [ 'options' => ['name' => 'information_orientation'], 'type' => switchinput::radio, ....
from docs:
options
: array html attributes widget input tag.
edit:
can use following
// value: $("[name='information_orientation']").val() // check if switch or on off $("[name='information_orientation']").prop('checked')
Comments
Post a Comment