kazupon / vue-validator

:white_check_mark: Validator component for Vue.js
MIT License
2.19k stars 431 forks source link

"$validate(true);" can manually validate all form fields, but how to manually validate specific field? #248

Closed postgetme closed 8 years ago

postgetme commented 8 years ago

eg: does support "$myValidator.phone(true)" ?

kazupon commented 8 years ago

You can use $validate the below.

<validator name="validation" @submit="onSubmit">
  <input type="text" detect-change="off" detect-blur="off" v-validate:username="{ required: { rule: true, initial: 'off' }, minlength: { rule: 8, initial: 'off' }}">
  <input type="submit" value="submit">
</validator>
new Vue({
  methods: {
    onSubmit: function (e) {
      this.$validate('username', true, function () {
        console.log('validate done !!')
      })
      if (this.$validation.invalid) {
        e.preventDefault()
      }
    }
  }
})

see the docs http://vuejs.github.io/vue-validator/en/api.html http://vuejs.github.io/vue-validator/en/timing.html

postgetme commented 8 years ago

@kazupon thank you very much!