DateField in HTML forms #8611
-
The docs state that in HTML forms, the "value will be submitted to the server as an ISO 8601 formatted string according to the granularity of the value." It's not 100% clear to me what to expect in this case: import { parseAbsoluteToLocal } from "@internationalized/date";
import { DateField, DateInput, DateSegment } from 'react-aria-components';
function Example() {
return (
<form
onSubmit={(e) => {
e.preventDefault();
alert(new FormData(e.currentTarget).get("date"));
}}
>
<DateField
aria-label="Date"
defaultValue={parseAbsoluteToLocal(new Date("2025-01-01").toISOString())}
granularity="day"
name="date"
>
<DateInput>
{(segment) => <DateSegment segment={segment} />}
</DateInput>
</DateField>
<button>Submit</button>
</form>
)
} SHould "2025-01-01" or "2025-01-01T01:00:00+01:00[Europe/Vienna]" be submitted. I would have expected the former (because of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
It uses the full value. The granularity prop only affects what is displayed, not the actual value. You can convert it to a CalendarDate if you want to remove the time part of the value. https://react-spectrum.adobe.com/internationalized/date/ZonedDateTime.html#to-a-date-or-time-only |
Beta Was this translation helpful? Give feedback.
Perhaps "type of the value" would be clearer in the docs. The format depends if it's a CalendarDate, CalendarDateTime, ZonedDateTime, etc.
For your second question, you can control the format of the empty state with the placeholderValue prop (eg passing a ZonedDateTime).