Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getInputProps(field, {type: "date"}) should convert dates to proper formats #523

Open
lifeiscontent opened this issue Mar 18, 2024 · 0 comments

Comments

@lifeiscontent
Copy link
Contributor

Describe the bug and the expected behavior

currently I'm having to do this:

  const [form, fields] = useForm({
    id: params.contact_id,
    defaultValue: {
      contact: {
        ...loaderData.contact,
        bday: loaderData.contact.bday
          ? getISODateStringFromISODateTimeString(loaderData.contact.bday)
          : undefined,
      },
    },
    lastResult,
    constraint: getZodConstraint(schema),
    onValidate({ formData }) {
      return parseWithZod(formData, { schema });
    },
    shouldRevalidate: 'onInput',
    shouldValidate: 'onBlur',
  });

where the function looks like:

export function getISODateStringFromISODateTimeString(
  dateString: string,
): string {
  const [date] = dateString.split('T');

  if (!date) {
    throw new Error('Invalid date string');
  }

  return date;
}

it'd be nice if getInputProps handled this case for us for date type

Conform version

latest

Steps to Reproduce the Bug or Issue

  1. create a zod schema with a z.date()
  2. set the field in defaultValue to a full ISO8601 Date string e.g. new Date().toISOString()
  3. see that the date field isn't pre-populated

What browsers are you seeing the problem on?

No response

Screenshots or Videos

No response

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant