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

yiiActiveForm ajax validation duplicate error messages in summary #16884

Open
yuniorsk opened this issue Nov 12, 2018 · 1 comment
Open

yiiActiveForm ajax validation duplicate error messages in summary #16884

yuniorsk opened this issue Nov 12, 2018 · 1 comment
Labels
JS JavaScript related status:to be verified Needs to be reproduced and validated. type:bug Bug

Comments

@yuniorsk
Copy link
Contributor

Right now there is inconsistency between server-side and client-side version of displaying error summary as server-side version shows only unique error messages and client-side shows all of them. As far as I can tell there's also no way to alter that behavior on client-side as summary rendering is done after the afterValidate event was triggered.

What steps will reproduce the problem?

ActiveForm with AJAX validation with multiple validation errors with same message (e.g. "Field is required").

What is the expected result?

Display only unique error messages and skip duplicates.

What do you get instead?

All error messages no matter if they is a duplicate or not.

@samdark samdark added type:bug Bug status:to be verified Needs to be reproduced and validated. JS JavaScript related labels Nov 12, 2018
@vadgus
Copy link

vadgus commented Jan 16, 2021

If someone uses old yii2 versions and cannot upgrade by some reasons:

$this->registerJs(<<<JS

$('div.error-summary ul').on('DOMSubtreeModified', function () {
    let uniqueErrors = {};
    $(this).find('li').each(function () {
        let thisVal = $(this).text();
        if (thisVal in uniqueErrors) {
            $(this).remove();
        } else {
            uniqueErrors[thisVal] = true;
        }
    })
});

JS
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JS JavaScript related status:to be verified Needs to be reproduced and validated. type:bug Bug
Projects
None yet
Development

No branches or pull requests

3 participants