You need to hang the js handler on your <select>
and, depending on the type chosen, show / unlock or hide / block the required fields.
If you have only 2 fields then you can arrange to switch types using input:radio
:
$this->registerJs(<<<JS $('#type_switcher input:radio').on('click', function() { $('#type_switcher').find('input:not(:radio)').each(function(){ this.disabled = true; }); $(this).closest('.form-group').find('input:not(:radio)').each(function(){ this.disabled = false; }); }); JS );
Display fields for the form
<div id="type_switcher" class="form-group" style="margin-left: 0; margin-right: 0;"> <?= $form->field($model, 'file') ->fileInput([ 'class' => 'form-control', 'disabled' => $model->type != $model::TYPE_FILE ]) ->label( Html::activeRadio($model, 'type', [ 'value' => $model::TYPE_FILE, 'label' => $model->getAttributeLabel('file'), 'id' => Html::getInputId($model, 'type') . '_' . $model::TYPE_FILE, ]) ) ?> <?= $form->field($model, 'value') ->textInput([ 'maxlength' => true, 'disabled' => $model->type != $model::TYPE_VALUE ]) ->label( Html::activeRadio($model, 'type', [ 'value' => $model::TYPE_VALUE, 'label' => $model->getAttributeLabel('value'), 'id' => Html::getInputId($model, 'type') . '_' . $model::TYPE_VALUE, 'uncheck' => null, // !!! ]) ) ?> </div>