Yii2输入字段集禁用依赖于其他字段

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]) ?>
...

First of all, add the script at the bottom of your view or add it into the $(document).ready();

Now, the code to change the name field depending upon user_id field.

$('#contact-user_id').change(function(){
    if ($(this).val() != 0 || $(this).val() != '') {
       $('#contact-name').attr('disabled',true);
    }
});