这是我的表单代码。
<?=$form->field($model, 'role_id')->widget(Select2::classname(),
[
'data' => ArrayHelper::map(RoleUser::find()->all(),'id','name'),
'options' => ['placeholder' => 'Select Role'],
'pluginOptions' => [
'allowClear' => true,
// 'minimumInputLength' => 1,
],
]);
?>
<?=$form->field($model, 'group')->widget(Select2::classname(),
[
'data' => ArrayHelper::map(Group::find()->all(),'group','group_name'),
'options' => ['placeholder' => 'Select Group 1'],
'pluginOptions' => [
'allowClear' => true,
'minimumInputLength' => 1,
],
]);
?>
<div id="group2">
<?=$form->field($model, 'group_id2')->widget(Select2::classname(),
[
'data' => ArrayHelper::map(Group::find()->all(),'group_id','group_name'),
'options' => ['placeholder' => 'Select Toko 2'],
'pluginOptions' => [
'allowClear' => true,
'minimumInputLength' => 1,
],
]);
?>
</div>
<div id="group3">
<?=$form->field($model, 'group_id3')->widget(Select2::classname(),
[
'data' => ArrayHelper::map(Group::find()->all(),'group_id','group_name'),
'options' => ['placeholder' => 'Select Toko 3'],
'id' => 'group_name3',
'pluginOptions' => [
'allowClear' => true,
'minimumInputLength' => 1,
],
]);
?>
</div>
<?php
$script = <<< JS
$(document).ready(function() {
$('#email').focus();
$('#group2').hide();
$('#group3').hide();
$('#s2id_register-form-role_id').on('change',function(){ // name is the id of select-box
if($(this).val() == 'admin_group'){ // check selected value is equal to admin_group
$('#group2, #group3').show();
} // if yes then show both div
});
});
JS;
$this->registerJs($script);
?>
如果role_user上的选定值为admin_group,我想显示输入表格组2和组3。 所以在defaut形式中,它应该只显示role_user和group1形式。有人可以帮帮我吗?感谢。
我编辑了javascript。但它仍然无法发挥作用。