horprogs / Just-validate

Modern, simple, lightweight (~5kb gzip) form validation library written in Typescript, with no dependencies (no JQuery!). Support a wide range of predefined rules, async, files, dates validation, custom error messages and styles, localization. Support writing custom rules and plugins.

Home Page:https://just-validate.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

removeField clears all errors when called

ceciiiron opened this issue · comments

commented

removeField clears all of the other errors when called. It should clear the errors or styles only to the selected field. The documentation says it too that it removes validation rules/events/errors from the particular field.

https://codesandbox.io/s/justvalidate-issue-118-sfytl3?file=/index.html

To reproduce bug

  1. Submit the form to show all errors.
  2. Create a trigger to call removeField() and it will remove all of the errors.

I have "Others" input field. It shows when I select "others" option from the dropdown. I also have an onchange event attached to it, wherein it adds an "others" field as required. When I select a different option, I remove the "others" field. However, when I call removeField from my onChange, it removes all of the errors from the form.

https://github.com/horprogs/Just-validate/assets/62165191/31010fe7-af59-4033-a9a9-84608691e172

Is there any other way to override the removeField function and remove the error style and label for a specific field only and not all of the errors?

Hey thanks for the report. Yeah it's a bug actually. For some reason I remove all errors (not sure what use case it was). Needs to be fixed

commented

removeGroup() also clears all of the errors. Thanks for the reponse