If your booking, availability or age-gate form already lives in HTML, adding detected form widget date input min max validation does not mean rebuilding the page. The Detected Form widget connects an existing form to WidgetJar — it does not replace your markup, your action URL or your field attributes. So the date limits you set on <input type="date"> stay native browser behavior, and your job is to set them correctly and then prove they still fire after the embed goes in.
This guide covers the field-level work: writing min and max, keeping the limits readable next to labels, writing error text that names the allowed range, and running a repeatable test pass in each browser you support. It assumes you already have a working form and the WidgetJar embed installed on your registered domain.
What native `min`/`max` actually does, and what the widget leaves alone
For numeric and date inputs, the min and max attributes define the allowed range. Per MDN's guide to client-side form validation, a value outside that range makes the field invalid, and when the user submits, the browser blocks submission and shows an error message.
The same source explains the validation states you can style: a valid control matches :valid, an invalid one matches :invalid, and date and numeric inputs may also match range-specific states such as :out-of-range. Those pseudo-classes give you styling hooks without any JavaScript.
Two practical consequences for your embed:
- The widget does not need to know about
min/max. Leave the attributes on the input element itself, not on a wrapper. - Native validation runs at submit time regardless of who wired up the form. If a submit handler calls a WidgetJar endpoint, the browser still runs constraint validation first, provided the submit goes through the form element.
If you have followed our earlier field guides on the required field asterisk or conditional show/hide logic, this is the same pattern: the widget is a layer, and your attributes remain the source of truth.
Setting `min` and `max` field by field
Static ranges
For a fixed range — say a booking window between two known dates — write the attributes literally. Use the same YYYY-MM-DD format the value attribute expects:
<label for="visit-date">Preferred visit date</label>
<input
type="date"
id="visit-date"
name="visit_date"
min="2026-01-05"
max="2026-06-30"
aria-describedby="visit-date-hint"
required
>
<p id="visit-date-hint">Choose any date between 5 January and 30 June 2026.</p>
Computed ranges
If the window rolls forward (for example, always from today to ninety days ahead), compute the values at page load and set them with setAttribute. Compute once, store the result, and use the same strings for the attribute and the hint text so they never drift apart. A caution from MDN worth remembering: length constraints are only reported for user input, so make sure your computed values are set before the user interacts, and test what happens if a value was prefilled programmatically.
Keeping attributes readable
Long inline attributes make templates hard to review. Keep the label, the hint paragraph and the input adjacent in the source so a reviewer can see the label text, the allowed range and the attribute values together. If you generate dates from a CMS field, output the raw YYYY-MM-DD string into the attribute and a human-readable version into the hint — never the other way round.
Writing messages that explain the range
A native browser bubble is brief. Users who hear the field through a screen reader need the same information in text they can revisit. Link a hint to the input with aria-describedby, as in the example above, and put the allowed dates in the hint.
For error wording after a failed submit, follow the same plain-language rules we cover in contact form error messages: name the field, state the problem, and say what to do next. "Visit date must be between 5 January and 30 June 2026" beats "Invalid date."
If you want the browser message itself to be clearer, our guide to customizing native HTML form validation messages walks through reading validity flags and using setCustomValidity — just remember to clear the custom message when the value changes, or the field stays invalid.
Edge cases after the widget connects
- Format expectations. The
minandmaxattributes requireYYYY-MM-DD. A locale-style value in the attribute silently fails to constrain anything, and the field accepts dates you meant to block. - Empty optional fields. An empty optional date field is not invalid just because
minexists. Test it: leave the field blank and submit. - Minimum greater than maximum. If you compute one bound from user state and hard-code the other, you can invert them. An impossible range makes every value invalid. Add a guard where you compute the values.
- Typed versus picked. A visitor can type digits into the date segments instead of using the picker. Both paths must be tested, because the browser validates the resulting value, not the interaction.
- Optional fields and
:invalidstyling. If you style:invalidheavily, check the empty-state look on optional fields so users are not warned before they have entered anything.
A repeatable test pass
Run this after every change to the form, and at least once after the widget embed is in place. Repeat it in each browser you support, since native messages differ.
- Keyboard entry. Tab to the date field, type an in-range date using the keyboard only, submit. Expect success.
- Picker entry. Pick an in-range date with the picker and submit. Expect success.
- Out-of-range submit. Type a date before
minand submit. Expect blocked submission, a browser message, and focus landing on the field. - Out-of-range after
max. Repeat with a date aftermax. - Empty submit on a required field. Submit with nothing entered. Expect the required message, not the range message.
- Empty submit on an optional field. Submit with the field blank. Expect the form to send.
- Computed bounds. If dates are computed, load the page, confirm the attribute values in DevTools, then run steps 1–4 again.
- Screen reader pass. Confirm the hint is announced with the field and that the error is reachable on return.
When native validation is not enough
The browser check is a first pass, not a security control. MDN's form data submission article notes that the action value should point to a file on the server that handles the incoming data, including server-side validation, and its companion validation article warns that a malicious user can alter the network request regardless of what the client does. So keep your range check on whatever endpoint receives the submission — the widget does not remove that responsibility.
Next step
If you have an existing HTML form and want to connect it to WidgetJar without rewriting your fields, start with the Detected Form widget: create and configure it in the panel, install the embed script on your registered domain, then run the test pass above before you publish the date range.
Reviewed for technical accuracy by James Holloway, Web Development Lead.