I have, a create form, where i ask two things. The first is a user_id the other is a name.
I want to achieve that, if the first is set then the other field will be disabled. And if because there i want to save that specific user's name. I tried it with javascript, but im so noob with js, thats why ask to you.
My codes is that:
$script = <<<JS
$('#contact-user_id').on('afterValidate', function (e) {
if ( $('#contact-user_id').value.length > 0 ) {
return document.getElementById("contact-name").disabled = true;
}
});
JS;
$this->registerJs($script);
?>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'user_id')->widget(Select2::className(), [
'value' => $model->user_id,
'data'=>ArrayHelper::map(User::find()->all(), 'user_id', 'name'),
'options'=>['placeholder'=>'Select User...'],
'pluginOptions' => [
'allowClear' => true
],
]) ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'email')->textInput(['maxlength' => true]) ?>
...