semisleep / simple-vue-validator

A simple yet flexible validator library for vue.js
MIT License
293 stars 28 forks source link

Validator is not defined #51

Open mikevelez opened 5 years ago

mikevelez commented 5 years ago

I'm using Vue2 I ran npm install --save simple-vue-validator

in my main.js file i have:

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import BootstrapVue from 'bootstrap-vue'
import SimpleVueValidation from 'simple-vue-validator';

Vue.use(SimpleVueValidation);
Vue.use(BootstrapVue);
Vue.config.productionTip = false;

import 'bootstrap/dist/css/bootstrap.css'
import 'bootstrap-vue/dist/bootstrap-vue.css'

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')

In my component script section I added:

validators: {
    'form.email': function (value) {
        return Validator.value(value).required().email();
    }
 },

and I run this on my submit:

 this.$validate()
.then(function(success) {
    if (success) {
        alert('Validation succeeded!')
    }
});

This looks like a great library but it's not working for me =/

semisleep commented 5 years ago

You need to also import {Validator} from 'simple-vue-validator' in the file that uses it.

johnsoncarneiro commented 5 years ago

I also get this, I tried importing Validator as mentioned above but no luck Property or method "validation" is not defined on the instance but referenced during render

semisleep commented 5 years ago

That might be because you don't have any validators defined.

SlivaNilow commented 5 years ago

import {Validator} from 'simple-vue-validator'

in each component? why not like router? this.$validator

Sookdeo commented 4 years ago

Hello, Did anyone got through with this issue? Please share answer. Thanks.

shahabgohar commented 4 years ago

Same Here . Works in one component only. get the same error when used in another component

mhariscoder commented 2 years ago
validators: {
    'form.email': function (value) {
        if( value != undefined ) {
              return Validator.value(value).required().email();
        }
    }
 },