Vee-validate: Error when submitting a form with scope and v-if: Error in directive validate unbind hook: "TypeError: Cannot convert undefined or null to object"

Created on 5 Sep 2017  路  2Comments  路  Source: logaretm/vee-validate

Versions:

  • VueJs: 2.4.2
  • Vee-Validate: 2.0.0-rc.14

Description:

After update to version 2.0.0-rc.14 I got the error on a form using scope:
Error in directive validate unbind hook: "TypeError: Cannot convert undefined or null to object"

I have two forms: the first, inside a v-if as the default option, is a login form with email and password fields. The second, inside the v-else, is a password reset form, with the email field only. Each one has it's own scope and they call different methods for handling the submit.

Log:

TypeError: Cannot convert undefined or null to object
    at Validator.detach (vee-validate.js?d4ab:3391)
    at unbind (vee-validate.js?d4ab:3824)
    at callHook$1 (vue.common.js?e881:5752)
    at _update (vue.common.js?e881:5716)
    at updateDirectives (vue.common.js?e881:5658)
    at Array.unbindDirectives (vue.common.js?e881:5652)
    at invokeDestroyHook (vue.common.js?e881:5277)
    at invokeDestroyHook (vue.common.js?e881:5281)
    at invokeDestroyHook (vue.common.js?e881:5281)
    at invokeDestroyHook (vue.common.js?e881:5281)

Steps To Reproduce:

  1. Start a project with Vue and Vee-validate on the versions above
  2. Create a form inside a v-if with scope (the if condition is the default)
  3. Submit the form and validate (alright so far)
  4. Redirect to another page on the same site (error)

Possible Solution:

The form I've submited had the scope 'login'.
The function where I've found the error is Validator.prototype.detach, line 3382 in the vee-validate.js file. The object flags does not contains the $login array, hence the error. The solution I've found was change this:

if (field.scope) {
    delete flags[("$" + (field.scope))][field.name];
  } else {
    delete flags[field.name];
  }

to this:

if (field.scope != undefined && flags[("$" + (field.scope))] != undefined) {
    delete flags[("$" + (field.scope))][field.name];
  } else {
    delete flags[field.name];
  }
duplicate

Most helpful comment

this was resolved and it should be up with the next release, duplicate of #788

All 2 comments

this was resolved and it should be up with the next release, duplicate of #788

Life saver

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MaxMilton picture MaxMilton  路  3Comments

Youdaman picture Youdaman  路  3Comments

DanielPe05 picture DanielPe05  路  3Comments

Hoagiex picture Hoagiex  路  3Comments

YamenSharaf picture YamenSharaf  路  3Comments