Search code examples
vue.jsvuelidate

How to add condition based url validation in vuelidate


I used vuelidate in my vue.js project form validation. It's works good.

But I need URL validation with a condition based. My requirement below.

My create meeting form have location type field & that based location info field.

Screenshots below:

Type - 1

enter image description here

Type - 2

enter image description here

If the user chooses virtual URL validate added. otherwise not to add URL validate.

If anyone has this solution Kindly share me.


Solution

  • I got my solution. It's based on validation callback return object.

    validations() {
      const self = this;
      return {
        model: {
          location: { required },
          location_info: {
            required,
            condUrlVald: self.model.location == 'V' ? url : required
          }
        }
      }
    },
    

    model.location is location type field variable. Value 'V' is location type 'Virtual'

    Refer by: https://github.com/vuelidate/vuelidate/issues/770#issuecomment-745101885