React Form - Getting Started
The Form component creates a data entry UI for the underlying data object. The interface consists of automatically-arranged label-editor pairs that correspond to data fields. You can change data values, validate user input, and send the resulting data to the server.
This tutorial shows basic Form component configuration.
Each section in this tutorial describes a single configuration step. The complete source code is available in the following GitHub repository:
Create a Form
Add DevExtreme to your React application and use the following code to create a Form:
- import React from 'react';
- import 'devextreme/dist/css/dx.fluent.blue.light.css';
- import { Form } from 'devextreme-react/form';
- export default function App() {
- return (
- <div className="App">
- <Form id="form">
- {/* Configuration goes here */}
- </Form>
- </div>
- );
- }
Populate the Form Fields
The Form creates a data entry UI when you assign an object to the formData property. The Form creates a simple item (a label-editor pair) for each field in the formData object.
The Form chooses default editors based on value types: a TextBox for string values, a NumberBox for numbers, and a DateBox for dates. You can use the editorType property to specify an editor explicitly. In the following example, the Form uses default editors:
- import { Form } from 'devextreme-react/form';
- const employee = {
- name: 'John Heart',
- officeNumber: 901,
- hireDate: new Date(2012, 4, 13)
- };
- export default function App() {
- return (
- <Form
- formData={employee}>
- </Form>
- );
- }
When you implement this code, the Form creates the following simple items: a TextBox for name, a NumberBox for officeNumber, and a DateBox for the hireDate data field.
Configure Simple Items
Use the items[] array to configure all form items. This array can contain strings (formData field names) and objects (item configurations). Use a string to create a label-editor pair (a simple item) with default configuration. To change the default settings, declare an item configuration object: specify the dataField and other properties. The following example configures the HireDate item:
- import { Form, SimpleItem } from 'devextreme-react/form';
- const employee = {
- name: 'John Heart',
- officeNumber: 901,
- hireDate: new Date(2012, 4, 13)
- };
- const hireDateOptions = {
- disabled: true
- };
- export default function App() {
- return (
- <Form formData={employee}>
- <SimpleItem dataField="name" />
- <SimpleItem dataField="officeNumber" />
- <SimpleItem
- dataField="hireDate"
- editorOptions={hireDateOptions}
- />
- </Form>
- );
- }
In Columns
The Form can organize items into a fixed number of columns or automatically adjust the layout based on the screen width. Initialize the colCount property as done in the following code to keep a fixed number of columns. To create an adaptive layout instead, configure the screenByWidth and colCountByScreen properties.
An item can span multiple columns. The following example sets the colSpan property for the Notes item to 2 so that it spans two columns.
- import { Form, SimpleItem } from 'devextreme-react/form';
- const employee = {
- name: 'John Heart',
- position: 'CEO',
- hireDate: new Date(2012, 4, 13),
- officeNumber: 901,
- notes: 'John has been in the Audio/Video industry since 1990.'
- };
- export default function App() {
- return (
- <Form
- formData={employee}
- colCount={2}>
- <SimpleItem dataField="name" />
- <SimpleItem dataField="position" />
- <SimpleItem dataField="hireDate" />
- <SimpleItem dataField="officeNumber" />
- <SimpleItem
- dataField="notes"
- colSpan={2}
- />
- </Form>
- );
- }
In Groups
You can use groups to organize data entry forms. Create a group item and nest other items within to add a group. You can nest items of any type in a group, including other group items. You can configure each group's layout separately.
The following code snippet creates two groups. Each group occupies a separate column. The resulting layout looks as follows:

- import { Form, SimpleItem, GroupItem } from 'devextreme-react/form';
- const employee = {
- name: 'John Heart',
- position: 'CEO',
- hireDate: new Date(2012, 4, 13),
- officeNumber: 901,
- phone: '+1(213) 555-9392',
- skype: 'jheart_DX_skype',
- email: 'jheart@dx-email.com'
- };
- export default function App() {
- return (
- <Form
- formData={employee}
- colCount={2}>
- <GroupItem
- caption="Personal Information">
- <SimpleItem dataField="name" />
- <SimpleItem dataField="position" />
- <SimpleItem dataField="hireDate" />
- <SimpleItem dataField="officeNumber" />
- </GroupItem>
- <GroupItem caption="Contacts">
- <SimpleItem dataField="phone" />
- <SimpleItem dataField="skype" />
- <SimpleItem dataField="email" />
- </GroupItem>
- </Form>
- );
- }
In Tabs
The Form uses the TabPanel component to display tabbed items. You can specify tab panel settings in the tabPanelOptions object. A tab can contain any item type.
The following example nests a tabbed item in the Personal Information group and configures the tab panel's height property. The resulting Form looks as follows:

- import { Form, SimpleItem, GroupItem, TabbedItem, Tab, TabPanelOptions } from 'devextreme-react/form';
- const employee = {
- name: 'John Heart',
- position: 'CEO',
- hireDate: new Date(2012, 4, 13),
- officeNumber: 901,
- phone: '+1(213) 555-9392',
- skype: 'jheart_DX_skype',
- email: 'jheart@dx-email.com',
- notes: 'John has been in the Audio/Video industry since 1990.'
- };
- export default function App() {
- return (
- <Form
- formData={employee}
- colCount={2}>
- <GroupItem caption="Employee">
- <SimpleItem dataField="name" />
- <SimpleItem dataField="position" />
- <SimpleItem dataField="hireDate" />
- <SimpleItem dataField="officeNumber" />
- </GroupItem>
- <GroupItem caption="Personal Information">
- <TabbedItem>
- <TabPanelOptions height={280} />
- <Tab title="Contacts">
- <SimpleItem dataField="phone" />
- <SimpleItem dataField="skype" />
- <SimpleItem dataField="email" />
- </Tab>
- <Tab title="Note">
- <SimpleItem dataField="notes" />
- </Tab>
- </TabbedItem>
- </GroupItem>
- </Form>
- );
- }
Add an Empty Space
Use an empty item to add an empty space between neighboring items. Assign "empty" to the itemType property to create an empty item, and specify the colSpan property to define how many columns the empty item should span. For a list of available properties, refer to the Empty Item section.
In the following example, the empty item spans two columns. The resulting layout looks as follows:

- import { Form, SimpleItem, EmptyItem } from 'devextreme-react/form';
- const employee = {
- // ...
- };
- export default function App() {
- return (
- <Form
- formData={employee}
- colCount={2}>
- <SimpleItem dataField="name" />
- <SimpleItem dataField="position" />
- <SimpleItem dataField="hireDate" />
- <SimpleItem dataField="officeNumber" />
- <EmptyItem
- colSpan={2}
- />
- <SimpleItem dataField="phone" />
- <SimpleItem dataField="skype" />
- <SimpleItem dataField="email" />
- </Form>
- );
- }
Configure Item Labels
You can configure individual labels in the label object. This object's section lists all available properties.
The following properties apply to all labels in the Form:
The following code configures the labelLocation property to place labels on top of editors. The example also configures the Notes item's label.alignment property to position label text in the center:

- import { Form, SimpleItem, Label } from 'devextreme-react/form';
- const employee = {
- // ...
- };
- export default function App() {
- return (
- <Form
- formData={employee}
- colCount={2}
- labelLocation="top">
- <SimpleItem dataField="name" />
- <SimpleItem dataField="position" />
- <SimpleItem dataField="hireDate" />
- <SimpleItem dataField="officeNumber" />
- <SimpleItem
- dataField="notes"
- colSpan={2}>
- <Label alignment="center" />
- </SimpleItem>
- </Form>
- );
- }
Modify the Form at Runtime
You can change any properties of the form, its items, or editors at runtime. To update a property value, bind it to a component property. The following code modifies the readOnly property's value:
- import React, {useState, useCallback } from 'react';
- import { Form } from 'devextreme-react/form';
- import { CheckBox, type CheckBoxTypes } from 'devextreme-react/check-box';
- const employee = {
- // ...
- };
- export default function App() {
- const [isFormReadOnly, setIsFormReadOnly] = useState<boolean>(false);
- const onCheckBoxValueChanged = useCallback((e: CheckBoxTypes.ValueChangedEvent) => {
- setIsFormReadOnly(e.value);
- }, []);
- return (
- <div>
- <Form
- formData={employee}
- readOnly={isFormReadOnly}>
- {/* ... */}
- </Form>
- <CheckBox
- text="Enable read-only mode"
- value={isFormReadOnly}
- onValueChanged={onCheckBoxValueChanged}
- />
- </div>
- );
- }
Validate the Form Data
DevExtreme includes a validation engine that checks edited values before they are saved. This engine supports different validation rule types.
Specify validation rules for a simple item in the validationRules[] array. You can specify an item's isRequired property to implicitly apply the RequiredRule.
The following example sets the isRequired property for the Name item. It also adds the NumericRule for officeNumber and the EmailRule for Email.
- import { Form, SimpleItem, NumericRule, EmailRule } from 'devextreme-react/form';
- // ...
- export default function App() {
- return (
- <Form
- formData={employee}
- colCount={2}>
- <SimpleItem dataField="name" isRequired={true} />
- <SimpleItem dataField="officeNumber">
- <NumericRule />
- </SimpleItem>
- <SimpleItem dataField="email">
- <EmailRule />
- </SimpleItem>
- </Form>
- );
- }
You can also call the Form's validate() method to validate all editors simultaneously.
Submit the Form
Add a Button Item and set its useSubmitBehavior property to true to submit a form. You can submit the Form to a server only if input validation is successful.
The useSubmitBehavior property requires that you wrap the dxForm in the HTML form element. You should also set the preventDefault property to true to override the HTML form submit event.
The following code snippet adds a submit button but does not implement the backend. The example displays a confirmation message after a timeout:
- import React, { useCallback } from 'react';
- import { Form, SimpleItem, GroupItem, ButtonItem, NumericRule, EmailRule } from 'devextreme-react/form';
- import notify from 'devextreme/ui/notify';
- const employee = {
- // ...
- };
- const submitButtonOptions = {
- text: "Submit the Form",
- useSubmitBehavior: true
- };
- export default function App() {
- const handleSubmit = useCallback((e: React.FormEvent<HTMLFormElement>) => {
- setTimeout(() => {
- notify('Submitted', 'success', 2000);
- }, 1000);
- e.preventDefault();
- }, []);
- return (
- <form action="/employee-page" onSubmit={handleSubmit}>
- <Form
- formData={employee}
- colCount={2}>
- <GroupItem
- caption="Personal Information"
- colCount={2}>
- <SimpleItem dataField="name" isRequired={true} />
- <SimpleItem dataField="officeNumber">
- <NumericRule />
- </SimpleItem>
- <SimpleItem dataField="email">
- <EmailRule />
- </SimpleItem>
- </GroupItem>
- <ButtonItem buttonOptions={submitButtonOptions} />
- </Form>
- </form>
- );
- }
Alternatively, if you want to implement custom validation logic, handle the Button click event:
- import { Form, ButtonItem } from 'devextreme-react/form';
- import notify from 'devextreme/ui/notify';
- const submitButtonOptions = {
- text: "Submit the Form",
- onClick: function() {
- const validationResult = formInstance.validate(); // get Form instance beforehand
- if (validationResult.isValid)
- document.getElementById("form-container").submit();
- else
- notify('Form is Invalid', 'error', 2000);
- }
- };
- export default function App() {
- return (
- <form action="/employee-page" id="form-container">
- <Form ... >
- <ButtonItem buttonOptions={submitButtonOptions} />
- </Form>
- </form>
- );
- }
To use the DevExtreme Form with the useActionState hook, call clear() at the start of the reducerAction function:
- import React, { useActionState, useRef } from "react";
- import { Form, SimpleItem, GroupItem, ButtonItem, NumericRule, EmailRule } from "devextreme-react/form";
- const employee = {
- // ...
- };
- const submitButtonOptions = {
- text: "Submit the form",
- useSubmitBehavior: true,
- };
- export default function App() {
- const form = useRef(null);
- const [error, submitAction, isPending] = useActionState(
- async (previousState, formData) => {
- form?.current?.instance?.().clear?.(); // Clear the form
- await new Promise((resolve) =>
- // Resolve the promise
- );
- if ( ... ) { // Configure when to return an error
- return new Error("Submitting failed!");
- }
- const fieldValues = Object.fromEntries(formData);
- return fieldValues;
- },
- null
- );
- return (
- <form action={submitAction}>
- <Form ref={form} formData={employee} colCount={1}>
- <GroupItem caption="Personal Information" colCount={1}>
- <SimpleItem dataField="name" isRequired={true} />
- <SimpleItem dataField="officeNumber">
- <NumericRule />
- </SimpleItem>
- <SimpleItem dataField="email">
- <EmailRule />
- </SimpleItem>
- </GroupItem>
- <ButtonItem
- horizontalAlignment="left"
- buttonOptions={{ ...submitButtonOptions, disabled: isPending }}
- />
- </Form>
- </form>
- );
- }
For more information on the Form UI component, refer to the following resources: