FormField
A responsive container for Forge inputs with added user-friendly features, designed for use inside Form.
The Basics
What it is
FormField bundles all the functionality needed to make the inputs in a form intuitive and accessible. This includes a label, hint text, and room for error messaging. It is designed for use inside the Form component.
How it works
- The user clicks or focuses on an input wrapped in FormField, which makes it active.
- While the field is active, the user can add and edit data in it.
- If the field has validation or required field checking (not built in; must be implemented by your team) and the user-entered data doesn’t match the validation rules, an error appears next to or below the field on submit.
When to use
- To enable responsive, user-friendly features for Forge inputs
- When designing forms that should follow the typical Forge layout and styling
- To build a form quickly without having to spend time customizing layout and styles
When not to use
- For a standalone form input that doesn’t need any of the features enabled by FormField
What to use instead
Use MultiField to group related inputs on the same line.
How to use
FormField is designed for use inside the Form component. Use FormField to display a single input field. To display a group of related fields, use MultiField instead.
Input validation
FormField (and its container, Form) do not have built-in input validation (code that checks user-entered data against a set of expectations and flags any errors) or required field checking. You can set a FormField to be required, but your team must build the code that confirms whether data has been entered in it.
FormField elements and options
FormField includes these elements:
- Input: This can be any Forge form input (like Checkbox, DateInput, or RadioGroup) or a custom-built component. It defaults to Input if no component has been specified.
- Label (required): Text that introduces the input and indicates what users should enter.
- Hint text (optional): Short instructional text displayed below the input that helps users enter data correctly (like “PDF files only”).
- Error message (optional): An input validation warning message that can be shown if there are problems with the user-entered data. Depending on the space available, this is displayed to the right of the input or below it. It can be set to always appear below the input.
These options can be set for FormField:
- Required: Setting a FormField as required means that users must enter data in its input. The visual treatments for required fields are set for the entire parent Form. See Form for the required field styles and help choosing the best one for your use case.
- Disabled: Setting a FormField as disabled allows you to display the input but prevent users from interacting with it. This is useful for temporarily deactivating it until a certain condition is met. For example, you may want users to know that there is a field for the appointment date, but you don’t want them to enter data in it until they select a clinic location.
These design aspects are set for the whole Form, but you can override them and set them for individual FormFields (to create complex form layouts):
- Layout: The level of visual density of the Form. This can be set to medium (default), compact, or super-compact.
- Label placement: Whether the label appears to the left of the input (and switches to above the input when the viewport shrinks) or it always appears above the input.
- Label space width: The amount of white space taken up by the label when it’s displayed to the left of the input (based on Forge’s Grid layout framework).
See the UX guidance for Form for full details about these design aspects.
Style
Design details
The height of this component and the vertical space around it vary according to the form layout (i.e., large, medium, compact, super-compact). See Form for details.
Placement and hierarchy
No additional information for this component.
Content
Use sentence case for the label ("Reason for visit”, not “Reason for Visit”) and the other text elements of FormField (hint text, error message, and any placeholder text inside the input).
Label
FormField requires a label for its input. Label text should be as short as possible and describe the data users should enter. Be aware that one of Form’s required field styles (the “Bar with “- Required” label” option) adds the text “ - Required” to the end of any required field’s label.
Don’t end your label text with colons (“First name”, not “First name:”).
Labels can have formatting, like bold text. Use this carefully because it can interfere with users being able to quickly scan through form fields. Don't design labels with links or other clickable features inside them. This can interfere with native browser handling for form labels.
Hint text and placeholder text
Hint text (optional) is displayed below the input field. Use this for very short instructions about the input. For example:
- “Maximum file size is 25 MB”