0

I am trying to validate data between to years using the object notation like followed:

<div class="form-group">
    <label for="construction-year">Construction Year</label>
    <input v-validate="validations.building.construction_year" data-vv-as="Construction Year" v-model="construction_year" type="text" id="construction-year" class="form-control" name="construction_year" placeholder="Year" maxlength="4">
    <div v-show="errors.has('construction_year')" id="construction-year-error" class="msg-error text-danger">{{ errors.first('construction_year') }}</div>
</div>

<script>
  data() {
    return {
      validations: {
        building: {
          construction_year: {
            required: true,
            date_format: 'YYYY',
            date_between:`1500,${new Date().getFullYear()}`
          },
          floors_above_ground: {
            required: true,
            between: '1,11',
          },
        }
      },
    }
  },
</script>

However, the message that I am getting is:

The Construction Year must be between 1500,2018 and undefined.

How would be the right way to do it? In the documentation, it is not shown the object notation, so I tried to pass a string but it did not work either. The same problem is happening when I am using the validation 'between' as illustrated above.

Thanks for the help in advance.

1 Answers1

0

When I was trying to create a custom validation as a workaround to this error, I realized that the args parameter, which the Custom validator receives, is an array.

So, I tried to use an array to the between and data_between validations in the object notation and it worked as followed.

validations: {
  building: {
    construction_year: {
      required: true,
      date_format: 'YYYY',
      date_between: ['1500', `${new Date().getFullYear()}`],
    },
    floors_above_ground: {
      required: true,
      between: [1, 11],
    },
  }
},

It would be good to add this information in the Documentation.