vuelidate validators code example

Example 1: npm install vuelidate

npm install vuelidate --save

Example 2: vuelidate required if another props

elements: {
            $each: {
              type: {
                required,
              },
              question: {
                required: requiredIf(prop => prop.type === 'input'),
              }
            }
          }

Example 3: vuelidate same as

validations: {
    form: {
      old_password: {
        data: { required },
      },
      new_password: {
        data: { required },
      },
      repeat_password: {
        data: { 
          sameAsPassword: sameAs(function() {
            return this.form.new_password.data;
          }) 
        },
      },
    },
  },

Example 4: vuelidate custom validation

const price_greater = (value, vm) => (value >= vm.min_price);
validations: {
    user_price: {
         required,
         price_greater
       }
}

Example 5: vuelidate require if

required: requiredIf(()=> { return condition })

Tags:

Misc Example