Skip to content

Add atomic fields validation/re-validation mode #122

Description

@vasilii-kovalev

Proposal

Currently, even when setting validate: "change", when the user changes a value in one of the fields, all the fields in the form are validated, and all the related errors are shown.

This ticket is a request to implement the same approach as in React Hook Form with mode: "onChange". In this case, when the user changes a value in one of the fields, an error (if any) is displayed only for that field, and all the fields are validated at once only on submit.

The same goes for revalidate/reValidateMode.

I think it is a balanced UX approach, because the alternatives have problems:

  • With validation on submit (default for Formisch), if there are validation issues, users need to go and fix them in the fields they already touched before = double work
  • With validation for all the fields on change in one of them (with validate: "change"), users are overwhelmed by all the appeared errors

Performance

The whole schema is validated on each keystroke now anyway when validate: "change" is used (from what I understand), so it is only necessary to update the errors state more atomically. No performance degradation expected.

Additionally I was thinking about if Formisch could run only the relevant checks from the provided schema using

  • pick to get the main checks for the related field AND
  • Check for the field's name in partialCheck, and if it is there, run such validations as well (not sure if Zod and other libraries could provide the means for that like Valibot does, though) AND
  • If there are custom validations that can't provide a clear information, what fields are used inside, run them just in case

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestpriorityThis has priority

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions