Skip to main content

Common Examples

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

function ExampleComponent() {
  return (
    <FieldMessage
      hint="Hint text"
      description="Description text"
      errorMessage="Please provide a valid email."
    />
  );
}

You might not need FieldMessage

The FieldMessage component is used to display description text, help text, and error messages beneath form components. Please look to our Form Patterns page for guidance on how to use hints, descriptions, and errors for your use case.However, many form components in Anvil2 already have FieldMessage built into them, such as Combobox, DateField, DaysOfTheWeek, TextField, and Textarea. For all of these components, you do NOT need to use the FieldMessage component, just use the existing props such as description and hint on your Anvil2 form components.

Accessibility

For accessibility, the FieldMessage component accepts an id prop that can be used to establish a relationship between the contents of the FieldMessage and the form component you are associating it with. To do this, you will likely need to use an ARIA attribute such as aria-describedby. See MDN docs.
import { useId } from "react";

function ExampleComponent() {
  const id = useId();

  return (
    <Flex direction="column" gap="2">
      <Button aria-describedby={id}>Move to trash</Button>

      <FieldMessage
        id={id}
        description="Items in the trash will be permanently removed after 30 days."
      />
    </Flex>
  );
}
For more guidance on form field labels and context, see input field context association best practices.
Last modified on January 23, 2026