data-scope prevents initial validation
See original GitHub issueI have created a form with one text input, which has two validations, please see below.
Example 1 - without data-scope
form.col-xs-6
input-group
label.col-form-label.col-xs-4 email
.col-xs-8
input.form-control(v-model="email", v-validate="email", data-rules="required|email")
p.text-danger(v-if="errors.has('email')") {{ errors.first('email') }}
hr
pre {{ errors | json }}
Without data-scope
the above validations run immediately when the page is loaded and the error message is displayed accordingly. Also, I dump the errors
object below the form to see what errors are set, which looks like this:
{
"errors": [
{
"field": "email",
"msg": "The email is required."
},
{
"field": "email",
"msg": "The email must be a valid email."
}
]
}
Example 2 - with data-scope
With data-scope
set to form1
, as shown below, the validation error only shows once I enter some text into the input control.
form.col-xs-6(data-scope="form1")
input-group
label.col-form-label.col-xs-4 email
.col-xs-8
input.form-control(v-model="email", v-validate="email", data-rules="required|email")
p.text-danger(v-if="errors.has('email','form1')") {{ errors.first('email','form1') }}
hr
pre {{ errors | json }}
Please note that the dumped errors object is exactly the same initially as without data-scope
. Only after you enter at least one character in the input control do you get a new key in the dumped errors object, this time with a "scope": "form1"
.
{
"errors": [
{
"field": "email",
"msg": "The email is required."
},
{
"field": "email",
"msg": "The email must be a valid email."
},
{
"field": "email",
"msg": "The email must be a valid email.",
"scope": "form1"
}
]
}
Also, the examples in the documentation exhibit this same problem, please see http://vee-validate.logaretm.com/examples#scope-example.
Thanks for your help.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@philipzaengle a lot has been changed since then, actually there is hardly any initial validation occurring, and
.inital
modifier doesn’t do anything atm, I’m considering either leaving the default as no initial validation and.initial
forces validating on bind, so I’m looking to introduce a breaking change by reversing the effect of.initial
@logaretm I have created a codepen with examples that illustrate the problem http://codepen.io/pbastowski/pen/bBovBO?editors=1000
There are three sections in the example. The first two use
data-vv-scope
and the last one does not. The last one works as expected.