Field
A form row that ties one control to its label, description and error.
Dify sends extension requests to this base URL.
Usage guidelines
- Use
Fieldwhen one control needs a sharedname, a label, a description, validation or an error. Group several related controls withFieldset, and submit fields together with aForm. - A
Fielddescribes one control. A composite that renders its own controls, such as a picker with controls in its popup, does not go inside one. - Name the control with a visible
FieldLabel: text inputs,Textarea, input-basedComboboxandAutocomplete, a singleCheckbox,SwitchandNumberField.Select,Sliderand the date and time pickers use their own label parts. Aplaceholderor a tooltip is never the only name. FieldDescriptionandFieldErrordescribe the control througharia-describedby. Do not add a second label or a competing description to the control.- Set
nameon theField. It keys the value in the submitted form values and the server errors thatFormmaps back to the field. - Pick one source of validity per rule: native constraint attributes such as
required,typeandminLength; avalidatefunction; orFormerrorsfrom the server. When application code owns validity, setinvalidon theFieldand renderFieldError matchonly while it is invalid.
See the forms guide for the full model.
Anatomy
The control is any dify-ui form control, such as Input, Textarea, Checkbox or Switch; it reads its ID, name and validity from the surrounding Field. FieldItem wraps each checkbox or radio option inside a group, see Fieldset. FieldValidity passes the current validity state to a render function for custom feedback.
Examples
Reading validity state
Native attributes (required, minLength, pattern) drive each matched FieldError so every message stays in your own words. FieldValidity passes the live validity flags and current value to a render function for custom feedback—such as showing the published URL once the slug is valid. Try a, My Bot or support-bot.
3 to 32 lowercase letters, digits or hyphens.
Custom validation
validate runs after the native constraints pass. Return a message for an invalid value and null for a valid one; a FieldError without children shows the returned message. This field uses validationMode="onChange", so it checks every keystroke: try _query, sys or User Query. Add validationDebounceTime when the check is a request.
Referenced in prompts as {{variable_name}}.
Validity owned by the application
When a form library or other application code decides validity, pass invalid to the Field and render FieldError with match while the field is invalid. match without a validity key shows the message regardless of state, so the condition belongs to the application. Replace the legacy key with a new app- key to clear the error.
Find the key under API Access in the app.
Checkbox or switch label
For a single checkbox or switch, wrap the control in FieldLabel so the whole label toggles it. The description still describes the control.
Lists the knowledge sources under each answer.
API reference
Field
Groups a form control with its label, description, error message, and validation state. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
render | ComponentRenderFn<HTMLProps, FieldRootState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: FieldRootState) => React.CSSProperties | undefined) | No default | |
disabled | boolean | false | |
name | string | No default | |
validate | ((value: unknown, formValues: Form.Values) => string | string[] | null | void | Promise<string | string[] | null | void>) | No default | |
validationMode | 'onBlur' | 'onChange' | 'onSubmit' | 'onSubmit' | |
validationDebounceTime | number | 0 | |
invalid | boolean | No default | |
dirty | boolean | No default | |
touched | boolean | No default | |
actionsRef | React.RefObject<FieldRootActions | null> | No default | |
className | string | ((state: FieldRootState) => string | undefined) | No default | |
| Attribute | Description |
|---|---|
data-disabled | Present when the field is disabled. |
data-touched | Present when the field has been touched. |
data-dirty | Present when the field's value has changed. |
data-valid | Present when the field is valid. |
data-invalid | Present when the field is invalid. |
data-filled | Present when the field is filled. |
data-focused | Present when the field control is focused. |
FieldDescription
A paragraph with additional information about the field. Renders a <p> element.
| Prop | Type | Default | Details |
|---|---|---|---|
className | string | ((state: FieldDescriptionState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, FieldDescriptionState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: FieldDescriptionState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-disabled | Present when the field is disabled. |
data-valid | Present when the field is in a valid state. |
data-invalid | Present when the field is in an invalid state. |
data-touched | Present when the field has been touched. |
data-dirty | Present when the field's value has changed. |
data-filled | Present when the field is filled. |
data-focused | Present when the field control is focused. |
FieldError
An error message displayed if the field control fails validation. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
match | 'badInput' | 'customError' | 'patternMismatch' | 'rangeOverflow' | 'rangeUnderflow' | 'stepMismatch' | 'tooLong' | 'tooShort' | 'typeMismatch' | 'valid' | 'valueMissing' | boolean | No default | |
className | string | ((state: FieldErrorState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, FieldErrorState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: FieldErrorState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-disabled | Present when the field is disabled. |
data-valid | Present when the field is in a valid state. |
data-invalid | Present when the field is in an invalid state. |
data-touched | Present when the field has been touched. |
data-dirty | Present when the field's value has changed. |
data-filled | Present when the field is filled. |
data-focused | Present when the field control is focused. |
data-starting-style | Present when the error message begins animating in. |
data-ending-style | Present when the error message is animating out. |
FieldItem
Groups individual items in a checkbox group or radio group with a label and description. Renders a <div> element.
| Prop | Type | Default | Details |
|---|---|---|---|
disabled | boolean | false | |
className | string | ((state: FieldItemState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, FieldItemState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: FieldItemState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-disabled | Present when the field is disabled. |
data-valid | Present when the field is in a valid state. |
data-invalid | Present when the field is in an invalid state. |
data-touched | Present when the field has been touched. |
data-dirty | Present when the field's value has changed. |
data-filled | Present when the field is filled. |
data-focused | Present when the field control is focused. |
FieldLabel
An accessible label that is automatically associated with the field control. Renders a <label> element.
| Prop | Type | Default | Details |
|---|---|---|---|
nativeLabel | boolean | true | |
className | string | ((state: FieldLabelState) => string | undefined) | No default | |
render | ComponentRenderFn<HTMLProps, FieldLabelState> | React.ReactElement<unknown, string | React.JSXElementConstructor<any>> | No default | |
style | React.CSSProperties | ((state: FieldLabelState) => React.CSSProperties | undefined) | No default | |
| Attribute | Description |
|---|---|
data-disabled | Present when the field is disabled. |
data-valid | Present when the field is in a valid state. |
data-invalid | Present when the field is in an invalid state. |
data-touched | Present when the field has been touched. |
data-dirty | Present when the field's value has changed. |
data-filled | Present when the field is filled. |
data-focused | Present when the field control is focused. |
FieldValidity
Used to display a custom message based on the field's validity. Requires children to be a function that accepts field validity state as an argument.
| Prop | Type | Default | Details |
|---|---|---|---|
children required | (state: FieldValidityState) => React.ReactNode | No default | |