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

Propagate ValidationObserver's errors added via setErrors #2380

Merged
merged 1 commit into from Sep 26, 2019
Merged

Propagate ValidationObserver's errors added via setErrors #2380

merged 1 commit into from Sep 26, 2019

Conversation

Borzik
Copy link
Contributor

@Borzik Borzik commented Sep 26, 2019

This PR enables error propagation, so calling setErrors on parent (form-level) observer will be enough and errors will be rendered even on providers which are children of nested observers.

Example of issue here: https://codesandbox.io/s/veevalidate-30-manually-setting-errors-iknf0

This will be quite useful for those who have such structure:

ValidationObserver(ref="form" tag="form")
  Tab
    ValidationObserver
      ValidationProvider
        input
  Tab
    ValidationObserver
      ValidationProvider
        input

Current implementation requires you not only to call setErrors on parent observer, but also on each nested ValidationObserver, so snippet like this has to be added every time:

this.$refs.form.observers.forEach((observer) => {
  observer.setErrors(response.data);
});

Note that this snippet is for one-level nesting. I'm not sure if anyone would need to have ValidationObserver > ValidationObserver > ValidationObserver, but then the code will be even more complicated.

If you think that it's better to keep setErrors simple, maybe another method should be added for this feature, I can make another PR.

Copy link
Owner

@logaretm logaretm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks!

@logaretm logaretm merged commit 1e567cc into logaretm:master Sep 26, 2019
@Borzik Borzik deleted the set-errors-propagation branch September 26, 2019 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants