Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[yii.activeForm] onBlur - validationDelay freezes #18422

Open
youra-h opened this issue Dec 6, 2020 · 5 comments
Open

[yii.activeForm] onBlur - validationDelay freezes #18422

youra-h opened this issue Dec 6, 2020 · 5 comments
Labels
help wanted JS JavaScript related status:ready for adoption Feel free to implement this issue. type:bug Bug

Comments

@youra-h
Copy link

youra-h commented Dec 6, 2020

What steps will reproduce the problem?

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?

What is the expected result?

What do you get instead?

The validation text will appear immediately

Additional info

Q A
Yii version 2.0.
PHP version 7
Operating system Windows
@samdark samdark added the JS JavaScript related label Dec 7, 2020
@samdark
Copy link
Member

samdark commented Dec 7, 2020

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,
]);

@samdark samdark closed this as completed Dec 7, 2020
@youra-h
Copy link
Author

youra-h commented Dec 7, 2020

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 оно не нужно.

@samdark samdark reopened this Dec 7, 2020
@samdark samdark added help wanted status:ready for adoption Feel free to implement this issue. type:bug Bug labels Dec 7, 2020
@samdark
Copy link
Member

samdark commented Dec 7, 2020

Alright. Sounds valid. Do you want to do a pull request?

@youra-h
Copy link
Author

youra-h commented Dec 7, 2020

Yes

@youra-h
Copy link
Author

youra-h commented Dec 7, 2020

Кстати 0 там тоже не поставить, потому что if 0 ? 0 : 200 = 200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted JS JavaScript related status:ready for adoption Feel free to implement this issue. type:bug Bug
Projects
None yet
Development

No branches or pull requests

2 participants