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

Observer.validate does not wait for observer state to be set #2686

Closed
hackel opened this issue Mar 10, 2020 · 1 comment
Closed

Observer.validate does not wait for observer state to be set #2686

hackel opened this issue Mar 10, 2020 · 1 comment
Labels
✨ enhancement a "nice to have" feature

Comments

@hackel
Copy link

hackel commented Mar 10, 2020

Versions

  • vee-validate: 3.2.1
  • vue: 2.6.10

Describe the bug
When awaiting an observer's validate method, the function returns before the observer's state (flags and errors) are available, due to the debounce delay in the computeObserverState watcher. This is causing my e2e tests to fail. In my case, my code checks both the validation result and then another computed prop which depends on the form having been validated.

e.g. if (!(await this.$refs.observer.validate() && this.$refs.observer.flags.validated))...

I have confirmed that setting the debounce delay to 0 in Observer.ts fixes the issue.

Expected behavior
I would have expected the validation flags to be available as soon as the validate promise resolves.

Desktop (please complete the following information):

  • OS: Linux
  • Browser Cypress / Electron (Chromium 78)
  • Version 3.8.3

This is the same issue described in #2660, but with a different desired outcome. I don't think the validate response itself should change, I just don't want it to return until it's actually complete.

In my debugging, I found I can resort to a really hacky workaround like this:

if (
    !(
        (await this.$refs.observer.validate()) &&
        (await new Promise(resolve => setTimeout(() => resolve(true), 50))) &&
        this.$refs.observer.flags.validated...
    )
)

Sometimes it passes with a delay as low as 30, but occasionally it needs more so I had to leave it at 50. No idea why I can't go down closer to 16.

I really didn't like that workaround, though, so instead I'm just tracking the validated state separately in my component. I just wish I could rely on the flags provided by the library. Perhaps the debounce function could return a promise that is included in the validate's Promise.all or something.

@logaretm logaretm added the ✨ enhancement a "nice to have" feature label Mar 11, 2020
@logaretm
Copy link
Owner

This came up a few times so far, I guess having the validate method account for the delay would be a more suitable. I will see what I can do this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement a "nice to have" feature
Projects
None yet
Development

No branches or pull requests

2 participants