davestewart / vee-element

Replaces Element UI's validation engine with Vee Validate
http://vee-element.netlify.com
MIT License
73 stars 8 forks source link

Demo source doesn't work well on the latest version of vee-validate #8

Open song4wk opened 5 years ago

song4wk commented 5 years ago

Hi, @davestewart

This is Song again~ ^-^

Last week I was mentioned the problem about vee-element just only work on the version 2.1.0-beta.9 of vee-validate.

https://github.com/davestewart/vee-element/issues/3

I think I found an easy way to solve the problem Cannot read property 'i18nDriver' of undefined like this:

import VeeValidate from 'vee-validate'

// import the vue
import Vue from 'vue'

const Validator =     @###VeeValidate.Validator

const validations = {}

const options = {}

// install vee-validate first
Vue.use(VeeValidate)

export default new VeeValidate.Validator(validations, options)

Validator.extend('picked', {
    validate (data, args) {
        const min = Number(args[0])
        const max = Number(args[1])
        const valid = args.length === 1
            ? data.length >= min
            : data.length >= min && data.length <= max
        return {
            valid,
            data
        }
    },
    getMessage (field, params, value) {
        const [min, max] = params
        return params.length === 1
            ? `The {field} field requires at least ${min} item${min > 1 ? 's' : ''}`
            : `The {field} field requires between ${min} and ${max} items`
    }
})

but I'm not sure it's a good way.

Is there a suggestion?

If there is no problem I think update the demo source ASAP will be better.

Thank you!