-
I noticed that it gets passed to an onSubmit handler if one is passed in but when using submit it looks like it just generates the FormData from the form target again. My specific use case is a date input. The value on the input is formatted like 01/30/2022. I wanted to use transform to convert this to ISO8601 format that my database accepts without having to do it manually in every remix action function. I assume there's a reason that it's the way it is but maybe not since the onSubmit gets the parsed zod data |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
If you're using zod, this transformation can be added to the zod schema. Then you'll get the transformed value both in const validator = withZod(z.object({
myDate: z
.string()
// I don't think these validations are built-in so these would be your functions
.refine(isDate)
.transform(toIsoDate),
}) Then in your action const result = await validator.validate(await request.formData());
if (result.error) return validationError(result.error);
// `myDate` is an ISO date string
const { myDate } = result.data; Or in your onSubmit=({ myDate }) => {
// `myDate` is an ISO date string
}) |
Beta Was this translation helpful? Give feedback.
If you're using zod, this transformation can be added to the zod schema. Then you'll get the transformed value both in
onSubmit
and when you validate in your action.Then in your action
Or in your
onSubmit