Forms
Datepicker is built to work inside a plain HTML <form>, not just a component-level state manager.
Native submission
Give it a name, and it renders a hidden real <input> so the date is included in the form's FormData and works with native validation:
<form>
<Datepicker label='Date of birth' name='dob' required />
</form>In range mode, name="stay" submits two fields: stay[start] and stay[end].
Typing dates
editable turns the field into a text input as well, for people who'd rather type a date they know than click to it:
<Datepicker label='Date of birth' calendar='BS' editable defaultMonth={new Date(2000, 0, 1)} />- Type the date in the displayed calendar:
2083-07-12,2083/7/12or2083.07.12, in Latin or Devanagari digits. - It's committed on Enter or when leaving the field, and shown back in the calendar's own digits.
- Text that isn't an allowed date (impossible, outside
minDate/maxDate, or disabled) is marked invalid on Enter and reverts when you leave. - Clearing the text clears the value.
- ArrowDown opens the calendar; the calendar button next to the field does too.
editable is for single dates; in range mode it's ignored. formatValue isn't used while editable, since the text has to stay typeable.
Submitted format
By default the submitted value is the AD date ('YYYY-MM-DD'). Use valueFormat='bs' to submit the BS date instead — handy when the calendar itself is displayed in BS:
<Datepicker calendar='BS' name='dob' valueFormat='bs' required />Validation states
requiredblocks native form submission while the value is empty.invalidapplies error styling (the--patro-dangertoken) and setsaria-invalid. Combine it with your own validation logic:
const [dob, setDob] = useState<Date | null>(null);
const [submitted, setSubmitted] = useState(false);
<Datepicker
label='Date of birth'
required
value={dob}
onChange={(picked) => setDob(picked?.date ?? null)}
invalid={submitted && !dob}
aria-describedby='dob-help'
/>;Other form-relevant props
| Prop | Purpose |
|---|---|
disabled | Can't be focused or opened |
readOnly | Focusable, shows its value, but can't be changed |
id, aria-label, aria-labelledby, aria-describedby | Passed straight to the input for label/description wiring |
data-*, inputClassName, inputMode | Test ids, your form library's input class, the mobile keyboard for editable |
onFocus / onBlur | For "touched" tracking with form libraries |
ref | Forwarded to the focusable field (the text input when editable), e.g. for a form library's focus-on-error |
Form libraries
onChange receives a PatroDate, not a DOM event, so a form library's register() spread doesn't work. Connect it as a controlled field instead.
react-hook-form, with Controller:
<Controller
name='dob'
control={control}
rules={{ required: true }}
render={({ field, fieldState }) => (
<Datepicker
ref={field.ref}
value={field.value}
onChange={(picked) => field.onChange(picked?.date ?? null)}
onBlur={field.onBlur}
invalid={!!fieldState.error}
/>
)}
/>Formik: set the value and the touched state by name, since the blur event's target isn't a named input:
<Datepicker
value={formik.values.dob}
onChange={(picked) => formik.setFieldValue('dob', picked?.date ?? null)}
onBlur={() => formik.setFieldTouched('dob')}
invalid={!!(formik.touched.dob && formik.errors.dob)}
/>Storing dates
PatroDate.date is local midnight of the picked day. JSON.stringify and toISOString() turn it into a UTC instant, which reads as the previous day for anyone east of UTC: in Nepal, 15 Oct becomes 2026-10-14T18:15:00.000Z. To store or send a date, use the ad (or bs) string, the same 'YYYY-MM-DD' value a native form submits. Date props take those strings back as they are:
const [dob, setDob] = useState<string | null>('2000-05-14');
<Datepicker value={dob} onChange={(picked) => setDob(picked?.ad ?? null)} />;Resetting
A native form reset (a type='reset' button or form.reset()) puts the Datepicker back to its defaultValue and calls onChange with it.
Inside dialogs
Escape closes only the popover, so a surrounding dialog stays open. A modal dialog keeps focus and clicks inside itself, so a popover portalled to document.body can't be used there. Leave portal off, or, if a scrolling area inside the dialog cuts the popover off, portal it into the dialog's content element:
const [content, setContent] = useState<HTMLDivElement | null>(null);
<Dialog.Content ref={setContent}>
<Datepicker portalContainer={content} />
</Dialog.Content>;Layout
The field is 288px wide by default. To fill a form column, set the --patro-input-width token:
.my-form ._patro_datepicker {
--patro-input-width: 100%;
}See the examples for complete, working forms: a registration form with a BS date of birth and a minimum age, a hotel booking with booked nights and a minimum stay, and a fully Nepali leave application that counts working days.