Skip to content

Field

A form row that ties one control to its label, description and error.

Dify sends extension requests to this base URL.

hero.tsx

Usage guidelines

  • Use Field when one control needs a shared name, a label, a description, validation or an error. Group several related controls with Fieldset, and submit fields together with a Form.
  • A Field describes 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-based Combobox and Autocomplete, a single Checkbox, Switch and NumberField. Select, Slider and the date and time pickers use their own label parts. A placeholder or a tooltip is never the only name.
  • FieldDescription and FieldError describe the control through aria-describedby. Do not add a second label or a competing description to the control.
  • Set name on the Field. It keys the value in the submitted form values and the server errors that Form maps back to the field.
  • Pick one source of validity per rule: native constraint attributes such as required, type and minLength; a validate function; or Form errors from the server. When application code owns validity, set invalid on the Field and render FieldError match only while it is invalid.

See the forms guide for the full model.

Anatomy

tsx
tsx

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.

validity.tsx

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}}.

custom-validation.tsx

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.

Legacy keys no longer work. Create a new key and paste it here.
external-invalid.tsx

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.

switch.tsx

API reference

Field

Groups a form control with its label, description, error message, and validation state. Renders a <div> element.

Base UI Field.Root docs

Data attributes
AttributeDescription
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.

Base UI Field.Description docs

Data attributes
AttributeDescription
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.

Base UI Field.Error docs

Data attributes
AttributeDescription
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.

Base UI Field.Item docs

Data attributes
AttributeDescription
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.

Base UI Field.Label docs

Data attributes
AttributeDescription
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.

Base UI Field.Validity docs