Skip to main content

Common Examples

import { DateFieldSingle } from "@servicetitan/anvil2";

function ExampleComponent() {
  return <DateFieldSingle defaultValue={new Date().toISOString()} />;
}

Default values

Default values can be included in DateFieldSingle to use the field in an uncontrolled mode.

Controlled usage

The DateFieldSingle can be controlled. This means you can maintain the state outside the component. Listen for new dates with onChange and supply a date into the value prop.

Validation

Understanding the object passed back in onChange is key to understanding how to validate this field.isDateValid will tell you if the last entered date is valid according to the props you’ve supplied (e.g. required, minDate, maxDate, and unavailable).isInputValid will tell you only if the underlying input is a parseable date — this does not consider whether the date is good according the other props.isInputEmpty will tell you if the underlying input has no digits entered.Typically, you will want to use these values together to determine the overall validity of the field. Though the simplest implementation may likely suffice to use only isDateValid.

Disabled hint text

The hint text can be disabled. If the hint text is disabled, ensure that the date format is displayed on the page.

Disable calendar popover

The display of the Calendar can be prevented by passing disableCalendar.
Last modified on January 23, 2026