Reputation: 205
My problem is that I need to validate my date using any validation library (joi, yup, superstruct..etc) and after that, I need to cast the date object to iso string
I use Flatpikr , react-hook-form , joi OR yup
This my approach at first glance
I tried to achieve the first approach via yup but no hope
I tried to make a pre and post transform in yup
I opened a question in their repository explaining my steps
https://github.com/jquense/yup/issues/1153
My approach in joi didn't succeed also
i used this code
joi
.date()
.iso()
.required()
.min(new Date())
.messages({
'any.required': `Required.`,
'date.format': `Required`,
'date.base': `Should be a type of number`,
'date.min': `The date should be in future`,
});
and i have used
{ convert : false }
in joi options to prevent joi from converting the values
when setting convert to false, all of my validation schemas succeed even if my variables was required or empty
Upvotes: 0
Views: 1673
Reputation: 205
Found an solution by using
.raw()
with joi
refrences : https://joi.dev/api/?v=17.3.0#anyrawenabled
Upvotes: 1