1👍
✅
Each input needs to be wrapped in a ValidationProvider
. Change this:
<input type="text" rules="required">
To this:
<ValidationProvider rules="required">
<input type="text" rules="required" v-model="something">
</ValidationProvider>
Additionally, somewhere, you need to actually define the rules you want to use, so at the top of the file I put this:
import { ValidationObserver, ValidationProvider, extend } from "vee-validate";
import { required } from 'vee-validate/dist/rules';
extend('required',required);
Working copy of your Code Sandbox (I also updated vee-validate and vue to the latest versions): https://codesandbox.io/s/vue-template-dj9jn
To actually get the behaviour mentioned in the example, instead of using the invalid
flag of ValidationObserver
, try using the handleSubmit
method like so:
<ValidationObserver tag="form" v-slot="{handleSubmit}" @submit.prevent>
...
<button @click="handleSubmit(submit)">Submit</button>
And your submit function would look like this:
submit() {
//anything you do here will only be called when the form is valid
}
Source:stackexchange.com