Date values and Yup Validation #282
-
Hi - having an issue with using Felte with Yup validation of Date values and html date input type control. Transform is required in order to ensure a Date type value is created whenever the value changes on the control in order to pass Yup validation - this works fine when date values change. However, the transform is also run on whatever is provided to initialValues which turns the result into a Date which the html input control doesn't understand. My goal is to ensure the birthdate html date input shows a valid date value when the form is loaded, but also that when the value changes, it's set as a Date value to pass Yup validation. A workaround of using birthdate as a string in Yup is undesirable as that means Date range and other Yup date type specific validation won't work. Repl below that illustrates the issue. I'd welcome input from the community on how to solve for this issue: https://svelte.dev/repl/75ea4f8a0aa34053b15549f0ab4f7ea5?version=4.2.8 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Update on this. I was able to workaround the problem after I found the castValues option on the Yup validator. This handy feature uses Yup to automatically convert from string date values (yyyy-MM-dd type format like the value from an input date type control) to Date() objects. Still not ideal as I need a generic transformer to convert initialValues that will have Date type values into stringified yyyy-MM-dd format values as accepted by the html date control. |
Beta Was this translation helpful? Give feedback.
Update on this. I was able to workaround the problem after I found the castValues option on the Yup validator. This handy feature uses Yup to automatically convert from string date values (yyyy-MM-dd type format like the value from an input date type control) to Date() objects. Still not ideal as I need a generic transformer to convert initialValues that will have Date type values into stringified yyyy-MM-dd format values as accepted by the html date control.