Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom rules #10

Open
glutaminefree opened this issue Nov 18, 2019 · 2 comments
Open

Custom rules #10

glutaminefree opened this issue Nov 18, 2019 · 2 comments

Comments

@glutaminefree
Copy link

glutaminefree commented Nov 18, 2019

Hi! Great library!
What about adding custom rules? Or regex rule at least? :)

@lukasborawski
Copy link

@cj maybe you can help with this one?

@jac0b95
Copy link

jac0b95 commented Jun 30, 2020

@glutaminefree

If You want to extend Vuelidation by custom rules just pass option object

Vue.use(Vuelidation, {
  methods: {
    customValidationRule(value, args) {
      console.log(value, args) // log to console to see how it looks
      const valid = false
      const msg = 'Some validation message'
      return [valid, msg]
    },
  },
})

and use it like this

vuelidation: {
    data: {
      first_name: {
        required: true,
        customValidationRule: true,
      },
    },
  },

Place where the magic happens:

vuelidation/src/index.js

Lines 161 to 166 in 63c188b

methods: {
...validations,
...options.methods,
...(this.$options.vuelidation.methods),
// ...(this.$options.vuelidation ? this.$options.vuelidation.methods : {}),
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants