kazupon / vue-validator

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

field located in child component from validator does not work #131

Closed revati closed 8 years ago

revati commented 8 years ago

If i have component with

<validator name="myValidator">
  <child-component></child-component>
</validator>

And child-component with

<input v-validate:username="['required']" />

vue validator is complaining Uncaught TypeError: Cannot read property 'validate' of undefined. It relays on this.vm.$options._validator but in child component it is undefined (because this is not the same)

Are there any reasonable ways how to pass validator to child component? Why <validator name="myValidator"> is required at all? Are there any drawbacks if each field is wrapped within new instance of <validator name="myValidator">?

kazupon commented 8 years ago

Thank you for your feedback.

Are there any reasonable ways how to pass validator to child component?

I recommend that you should wrap the validator element directive (<validator>) to your component (<child-component>) that has validatable element (e.g, input, checkbox), because validator element directive will check validatable elements of internal, and dynamically set the validation result to validator scope (prefixed with $).

kazupon commented 8 years ago

Close (in-activity)