vee-validate icon indicating copy to clipboard operation
vee-validate copied to clipboard

how to validate a javascript date object emited by a component with 3 inputs (DD, MM, YYYY)

Open erwanpoupard opened this issue 7 years ago • 1 comments

Versions

  • vee-validate: 2.2.0
  • vue: 2.6.10

Describe the bug Its not realy a bug, but a question. I've a compontent FormDate with 3 inputs, and a Date value. Is it possible to add the v-validate directive on my component ? ex : <form-date v-validate="'required'" v-model="myBirthDay">

Or my first idea was to add an hidden input, but i dont think its a good way.

Demo link https://codepen.io/erwanpoupard/pen/MRpwXP?editors=1111

erwanpoupard avatar Apr 10 '19 09:04 erwanpoupard

Yes, it is possible, The date rules do accept a JS date object, it won't be parsed and it will bypass the date_format constraints since it would be a valid date obj. Generally, vee-validate does not have constraints on the type of the value being validated, it can be anything, not just strings.

The caveats would be dealing with the invalid states, for example, someone inputs a 0 or empties one of the inputs, negative values. You would need to emit either null to trigger required or date object with NaN time.

logaretm avatar Apr 10 '19 10:04 logaretm