Magento 2.4 Custom form validation mage error duplication

Mage error component is duplicating error warnings on form inputs.

Steps to reproduce
-Submit blank login form;
-Fill the input and submit again;
-Remove the input field and submit blank form again.
-Click one more time on submit button.

Solution:-

When we write a js for the submission of the please confirm that the form is valid or not.

Give a condition and for the valid else condition add the following code to remove the duplicated error displayed on the page.


 $('.mage-error:nth-of-type(2)').remove();

The :nth-of-type(n) selector selects all elements that are the nth child, of a particular type, of their parent. Tip: Use the :nth-child() selector to select all elements that are the nth child, regardless of type, of their parent.

Leave a comment

Your email address will not be published. Required fields are marked *