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 enter image description here

When we change the value in dropDownList, the required field is added enter image description here

or

enter image description here

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; } 
  • And what does the right mean? - Mihanik71 pm
  • The value in the Type field, which returns dropDownList (string or image) - Vlad
  • Well, you must have something by default. Or should the previous values ​​be stored? - Mihanik71

0