Open danisetg opened 5 years ago
method 1:
<?=$form->field($model, '论文类型')->widget(SwitchInput::classname(), [
'name' => 'lwlx',
'type' => SwitchInput::RADIO,
'value' => -1,
'tristate' => true,
'items' => [
['label' => '期刊论文', 'value' => '期刊论文', 'options' => ['checked' => true]],
['label' => '论文集论文', 'value' => '论文集论文'],
['label' => '报纸论文', 'value' => '报纸论文'],
['label' => '集刊论文', 'value' => '集刊论文'],
['label' => '其他文章', 'value' => '其他文章'],
],
'pluginOptions' => ['size' => 'mini'],
'labelOptions' => ['style' => 'font-size: 12px'],
]);
method2:
<?php
$js = <<<JS
jQuery(function($) {
$("input[value='期刊论文']").prop('checked', true);
});
JS;
$this->registerJs($js, \yii\web\View::POS_END);
?>
Hi, I am trying to use this widget and it is really useful, I really like it, but I'm facing the following problem: I have an activeForm in wich under certain conditions I call a "populate()" javascript function for filling the form fields, but I can't manage to change the switch to its 'on' property. I am using it as a checkbox in the following way:
I have tried with:
$('#contactos-es_usuario').val(true); $('#contactos-es_usuario').prop('checked', true); $('#contactos-es_usuario').attr('checked', true); $('#contactos-es_usuario')[0].checked = true; With no results in any of these. When I check the element in the development tools, the checked property does change to true, but the switch remains the same.
I'd really appreciate give me any help with this. Thanks in advance