Hello!
When displaying errors, the effect of inhibition occurs.
When the onBlur event occurs for Input.type = "text", the error is displayed not immediately, but by timeout. Input loses focus, the Click event was executed on the mouse, and only an error appears. I removed everything I could from ActiveForm, but it still slows down. I started digging through the code, it turned out that there is such a check:
data.settings.timer = window.setTimeout(function () {
if (data.submitting || $form.is(':hidden')) {
return;
}
$.each(data.attributes, function () {
if (this.status === 2) {
this.status = 3;
$form.find(this.container).addClass(data.settings.validatingCssClass);
}
});
methods.validate.call($form);
}, validationDelay ? validationDelay : 200);
This code works from here:
$input.on('blur.yiiActiveForm', function () {
if (attribute.status == 0 || attribute.status == 1) {
validateAttribute($form, attribute, true);
}
});
In validateAttribute, the fourth parameter is validationDelay, guys, you can fix this and set the fourth parameter to 1. What are these 200ms for?
The validation text will appear immediately
| Q | A
| ---------------- | ---
| Yii version | 2.0.
| PHP version | 7
| Operating system | Windows
200 is default validation delay. That was introduced on purpose to give user some time before the validation is triggered. You can adjust it in your form via options:
$form = ActiveForm::begin([
'validationDelay' => 1,
]);
200 is default validation delay. That was introduced on purpose to give user some time before the validation is triggered. You can adjust it in your form via options:
$form = ActiveForm::begin([ 'validationDelay' => 1, ]);
Дело в том, что это не работает. Поэтому я завел такую задачу.
validateAttribute($form, attribute, true);
В эту функцию 4 параметром передается, вот это:
$form = ActiveForm::begin([
'validationDelay' => 1,
]);
Но дело в то, что для события Blur оно не передается и берется по умолчанию 200.
По сути validationDelay видимо был введен для события Input/Change, но для события Blur оно не нужно.
Alright. Sounds valid. Do you want to do a pull request?
Yes
Кстати 0 там тоже не поставить, потому что if 0 ? 0 : 200 = 200