Skip to content
This repository has been archived by the owner on Dec 25, 2017. It is now read-only.

Does vue-validator support validation on fields inside a v-for element? #137

Closed
aaronjpitts opened this issue Jan 16, 2016 · 7 comments
Closed

Comments

@aaronjpitts
Copy link

I cannot get this to work on fields inside a v-for element. Is this possible with the current version?

Great work so far! Thank you

@kazupon
Copy link
Owner

kazupon commented Jan 16, 2016

Yes.
You can use the validation with v-validate inside v-for directive.
Example:
https://github.com/vuejs/vue-validator/blob/dev/test/specs/directives/validate.js#L49

@aaronjpitts
Copy link
Author

Hello, that's great! I've noticed one problem though, v-model causes the code to break if it's used on a field inside the view-directive with the for items name. For example, the below breaks the code:

<validator name="validator">
  <div v-for="room in property.rooms">
    <input type="text" v-model="room.price" :field="'field' + $index" v-validate="{ minlength: 4 }">
    <span v-if="$validator['field' + $index].valid"> valid !!</span>
  </div>
</validator>

It will give an error saying 'Uncaught TypeError: Cannot read property 'price' of undefined'

Thanks for your time so far. This is a great module.

@kazupon
Copy link
Owner

kazupon commented Jan 17, 2016

Thank you for your providing codes 😸

I tried to reproduction 'Uncaught TypeError: Cannot read property 'price' of undefined' error, However, I could not reproduction.

Can you provide the the following info to me please ?

  • vue.js version
  • vue-validator version

@aaronjpitts
Copy link
Author

Hi,

I'm using the latest of both:

vue.js: 1.0.14
vue-validator version: 2.0.0-alpha.12

@kazupon kazupon added the bug label Jan 17, 2016
@aaronjpitts
Copy link
Author

Thank you very much for the prompt bug fix! :-) Great work!

@kwzm
Copy link

kwzm commented Sep 8, 2016

@zhoucumt
Copy link

hello ,I want to see this example: https://github.com/vuejs/vue-validator/blob/dev/test/specs/directives/validate.js#L49, but it is 404.Thank you!

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

No branches or pull requests

4 participants