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

this$1.vm.$el.querySelector is not a function #870

Closed
uoziod opened this issue Oct 5, 2017 · 1 comment
Closed

this$1.vm.$el.querySelector is not a function #870

uoziod opened this issue Oct 5, 2017 · 1 comment

Comments

@uoziod
Copy link

uoziod commented Oct 5, 2017

Versions:

  • VueJs: 2.3.3
  • Vee-Validate: 2.0.0-rc.18

Description:

Some of the validating forms of my app are dynamically embedded on pages. Thus, in some cases, the template of the component containing form could not be rendered yet, and hence it's template it's just an empty comment element. And once v-validate.initial confirmed relates to some element of the form, the library tries to find such element... in the comment, with querySelector. Where comment element doesn't have such method.

Finally, we end up with:

TypeError: this$1.vm.$el.querySelector is not a function
    at vee-validate.esm.js:4065
    at Array.forEach (<anonymous>)
    at Field.updateDependencies (vee-validate.esm.js:4047)
    at Field.update (vee-validate.esm.js:3943)
    at new Field (vee-validate.esm.js:3833)
    at Validator.attach (vee-validate.esm.js:4650)
    at bind (vee-validate.esm.js:5374)
    at callHook$1 (vue.esm.js:5855)
    at _update (vue.esm.js:5780)
    at Array.updateDirectives (vue.esm.js:5761)

Solution:

Just wrap:

    if (!el) {
      el = this$1.vm.$el.querySelector(("input[name=\"" + selector + "\"]"));
    }

In try/catch too, just like it's done for the previous querySelector call:

    if (!el) {
      try {
        el = this$1.vm.$el.querySelector(("input[name=\"" + selector + "\"]"));
      } catch (err) {
        el = null;
      }
    }
@logaretm
Copy link
Owner

logaretm commented Oct 5, 2017

Thanks for reporting this and providing a solution. closed in 0e61737

@logaretm logaretm closed this as completed Oct 5, 2017
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

No branches or pull requests

2 participants