Skip to content

Validation results for not-rendered fields are always present #4982

Description

@jak-ch-ll

What happened?

When using a validation schema in combination with useField components (such as <Field />), the validation results for currently not-rendered components are contained within errors and errorBag. As soon as they are rendered, the errors disappear.

My expectation would be that the rendering state of components has no impact on the validation results, which means there shouldn't be any errors until the user has interacted with the form.

Potential fix

I dug into the code and found out that it is probably an easy fix in useForms. The exit for not-rendered components needs to be after the two mode-specific exits (silent and `validated-only).

I would have opened a PR, but as per the Contribution Guide I created this issue first. Once I have the OK I can open a PR, just let me know

Reproduction steps

  1. Open the provided Stackblitz repro (an example from the docs just slightly modified)
  2. Click the `Toggle form button
  3. You will see the errors being filled while the form is hidden

Version

Vue.js 3.x and vee-validate 4.x

Demo link

https://stackblitz.com/edit/qklfvbys?file=src%2FApp.vue

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions