Vee-validate: Group validation

Created on 7 Nov 2017  ยท  4Comments  ยท  Source: logaretm/vee-validate

I want to validate the widgets in group. i mean if there are two field at least one field is required. is it possible?

โ” question

Most helpful comment

I guess it would be something in the lines of

<input v-validate="surNameRule" id="surName"/>
<input v-validate="nickNameRule" id="nickName"/>

<script>

export default {

....

  computed: {
    surNameRule() {
      return {
        required: !this.nickName
      };
    },
    nickNameRule() {
      return {
        required: !this.surName
      };
    },
  },

.....

};

</script>

All 4 comments

The rules are dynamic, so you could have the required-rule as a computed property, and set to false if any of the other fields are valid.

can you please provide me small example. i have two input field for surname and nickname. but i need at least one value either nickname or surname.

I guess it would be something in the lines of

<input v-validate="surNameRule" id="surName"/>
<input v-validate="nickNameRule" id="nickName"/>

<script>

export default {

....

  computed: {
    surNameRule() {
      return {
        required: !this.nickName
      };
    },
    nickNameRule() {
      return {
        required: !this.surName
      };
    },
  },

.....

};

</script>

@sqpdln Thanks for helping out with the issues!

here is an example: https://jsfiddle.net/logaretm/p0766ckj/1/

Was this page helpful?
0 / 5 - 0 ratings