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

Validating a non-existant field after a router push #709

Closed
NOA-Louis opened this issue Aug 8, 2017 · 5 comments
Closed

Validating a non-existant field after a router push #709

NOA-Louis opened this issue Aug 8, 2017 · 5 comments
Labels
✨ enhancement a "nice to have" feature

Comments

@NOA-Louis
Copy link

NOA-Louis commented Aug 8, 2017

Versions:

  • VueJs: 2.4.1
  • Vee-Validate: 2.0.0-rc.9

Description:

I have this error: [vee-validate] Validating a non-existant field: "#_bjyogp74h". Use "attach()" first. when I redirect users to another view.

Steps To Reproduce:

  1. Have a form
  2. Check validations
  3. Redirect user to another route
  4. You have this error because of the this.$router.push()

In my case, I want to redirect users to the sign in page once they registered:

signup() {
        this.$validator.validateScopes('#signin-form').then((result) => {
          if (result) {
            this.loading = true;

            this.axios.post('/users', this.form).then((res) => {
              this.loading = false;
              if (res.data) {
                console.log(res.data);
                this.$router.push('Home');
              }
            });
          }
        });
      },

The parent scope has this line:

<form id="signup-form" @submit.prevent="signup">
@logaretm logaretm added the 🤔 needs reproduction This issue requires a demo label Aug 8, 2017
@logaretm
Copy link
Owner

logaretm commented Aug 8, 2017

I just setup an example with it Vue router and it seems working properly:

https://jsfiddle.net/logaretm/8bbguLtc/

It would be helpful if you can recreate the issue in a fiddle.

@NOA-Louis
Copy link
Author

NOA-Louis commented Aug 8, 2017

Thanks for your answer.

I have made a fiddle to reproduce the error: https://jsfiddle.net/9a0ejmvx/1/.
I noticed the error appeared when I added the data-vv-delay attribute.

Edit: actually it seems to have a conflict between the data-vv-delay attribute and the router history. Because when I quickly focus an input which has the data-vv-delay and click "previous" with my browser before the end of the delay, then the error also appears.

@logaretm logaretm added ✨ enhancement a "nice to have" feature and removed 🤔 needs reproduction This issue requires a demo labels Aug 8, 2017
@logaretm
Copy link
Owner

logaretm commented Aug 8, 2017

I see, you would need to navigate after the delay:

https://jsfiddle.net/logaretm/9a0ejmvx/3/

I will try to take a look if this can be improved or avoided by canceling ongoing validations.

@NOA-Louis
Copy link
Author

Actually, it still happens when we press the "enter" key. But not when we click the button. I guess this is because when we push the "enter" key a field is still focused.

@logaretm
Copy link
Owner

It has been resolved, should be up with the next release.

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