Yii2: Readonly/disabled inputs still trigger AJAX validation, even if it's explicitly disabled

Created on 15 Jun 2018  路  5Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

  1. Have an ActiveForm with AJAX validation configured (in my case it's a yii\bootstrap\ActiveForm, but the validation attributes are in yii\widgets\ActiveForm, so it's likely others would be the same).
  2. Add a readonly or disabled attribute to any field and disable AJAX validation for that field, e.g.:
<?= $form->field($user, 'name')
    ->textInput([
        'readonly'               => 'readonly',
        'enableClientValidation' => false,
        'enableAjaxValidation'   => false,
    ])
    ->label(true) ?>
  1. Click on that field to focus, then click away to trigger validation.

What is the expected result?

No validation, because the field is readonly AND validation is disabled (normally, even readonly alone should suffice, there should be no focus/blur events for a disabled input, removing which would fix it in this case).

What do you get instead?

AJAX request for validation still goes through.

Additional info

The same happens if you replace readonly with disabled.
Also, in my case, the field had no rules defined, since it was taken from another model for display purposes only.

| Q | A
| ---------------- | ---
| Yii version | 2.0.15.1
| PHP version | 7.0.28
| Operating system | Windows 7
| Browser | Google Chrome v67

JS ready for adoption bug

Most helpful comment

docs

/*
 *@param array $options the tag options in terms of name-value pairs. These will be rendered as
 * the attributes of the resulting tag.
 */
textInput($options = [])

Is 'enableClientValidation' a tag attribute?

All 5 comments

Why don't you use forums for such questions?

You need to disable validation like this:

                <?= $form->field($model, 'number', [
                        'enableAjaxValidation' => false,  // <------------
                    ])->textInput(['readonly' => 'readonly']); 

                ?>

It's not a question, it's a bug. Now go pester someone else.

@jurchiks its ok, dont mind, he might be mistaken.

docs

/*
 *@param array $options the tag options in terms of name-value pairs. These will be rendered as
 * the attributes of the resulting tag.
 */
textInput($options = [])

Is 'enableClientValidation' a tag attribute?

@samdark This issue should be closed as it is a question more than a bug because the enableClientValidation should be provided as the field() parameter rather than textInput().

Was this page helpful?
0 / 5 - 0 ratings