Skip to main content

maxDate()

🧭 API map​

I want to…Details
See every accepted call styleSignatures
See common and advanced usageUsage and behavior
Customize messagesMessage configuration
Understand reactive constraintsReactive behavior
Return to the complete catalogBuilt-in validators

πŸ“ Signatures​

maxDate(maximum)
maxDate(maximum, message)
maxDate(maximum, options)

Reactive constraint arguments use a zero-argument function. The function may read signals and, where supported, return undefined to disable the constraint temporarily.

πŸ“– Usage and behavior​

Requires a valid date on or before an inclusive maximum:

const myForm = form({
appointment: field<Date>(null, [maxDate('2026-12-31')]),
todayOnly: field<Date>(null, [maxDate('today')]),
reactiveAppointment: field<Date>(null, [maxDate(() => bookingWindowEnd())]),
localAppointment: field<Date>(null, [
maxDate('2026-12-31', { parseAs: 'local' }),
]),
messagedAppointment: field<Date>(null, [
maxDate('2026-12-31', 'Choose an earlier date.'),
]),
momentAppointment: field<Date>(null, [
maxDate(moment('2026-12-31').toDate()),
]),
});

It accepts the same absolute dates, relative shortcuts, reactive sources, and parsing modes as minDate. null, undefined, and invalid current dates pass. An absent or invalid resolved limit disables the constraint. A failure is { kind: 'maxDate', maxDate, actual, message }. The normalized Date contributes to max() metadata.

These absent values are accepted by the public types and remain unchanged in the field. Add required when a value must be present; see optional values.

If untyped data passes null as the optional options argument, it uses the same defaults as omitting options. Validation remains active and no warning is emitted. TypeScript still rejects null options; omit the argument or pass undefined in typed code.

πŸ’¬ Message configuration​

Every failure has a default English message. Where supported, pass a string as the final argument or use an options object for a static or reactive message, as shown above.

A message function may read signals. Returning undefined continues through node, Angular provider, process-wide, and built-in message fallbacks. See Validator messages.

⚑ Reactive behavior​

The options object accepts a reactive when predicate. Signals read from its validator context are tracked; while it returns false, the rule contributes neither errors nor constraint metadata.

const enforceBookingWindow = signal(false);
const departure = field(new Date('2027-01-01'), [
maxDate('2026-12-31', { when: () => enforceBookingWindow() })
]);

Reactive constraint functions and message functions track the signals they read. When a resolved constraint becomes unavailable, validators that support optional constraint sources temporarily stop contributing their error and metadata.

The validator runs synchronously as part of its node's validator source. Disabled, readonly, and hidden nodes skip validation until they become interactive again.