How to make the transition to a page display the value that is in the dropDownList That is, when we go to the page we see
When we change the value in dropDownList, the required field is added
or
So the question is how to make sure that the right field is right when you go to the page
Here we form this code - selection field, text field, download field
<? $list = $form->field($model, 'type')->dropDownList([ 'string' => 'string', 'image' => 'image', ], ['class' => 'js-type']); ?> <?= $list ?> <div id="string" style="display:none;"> <?= $value; ?> </div> <div id="image" style="display:none;"> <?= $file; ?> </div>
Here is the script code js
$script = <<< JS $('.js-type').on('change',function(){ var selection = $(this).val(); switch(selection){ case "string": $("#string").show() $("#image").hide() break; case "image": $("#image").show() $("#string").hide() break; }