kazupon / vue-validator

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

Syntax / Nested fields in Dev #100

Closed JoshZA closed 8 years ago

JoshZA commented 8 years ago

Hey Kazupon

I have this use case

v-model="client.description"
v-validate:client.description.required

Does validator 2.0 support nested properties?

Is their no way to change v2 to automatically get the binding from v-model, so that we could just write

v-model="client.description"
v-validate:required

Also for this:

    ID: <input type="text" v-validate:id.minlength.maxlength="{ minlength: 3, maxlength: 16 }"><br />

Couldn't we get:

    ID: <input type="text" v-validate:id.minlength(3).maxlength(16)><br />
bradstewart commented 8 years ago

You can do something like:

<validator name="clientValidator">
  <input v-model="client.description" v-validate:description.required />
</validator>

And then in your Vue instance, this.$clientValidator.description will contain the value of the input field and all the relevant validation data for the field.

kazupon commented 8 years ago

Sorry for the late reply.

In v2.0, I decided that don't support the nested property, because application design become complex. Vue is the component oriented. I think that you can implement like the comment of @bradstewart, also use the component.

JoshZA commented 8 years ago

Ah ok, makes sense, thanks guys =)