# Getting Started with the KendoReact Form

This guide provides essential information about using the KendoReact Form package. You will learn how to install the package, add a Form component to your project, style the component, and activate your license.

<CtaPanelOverview></CtaPanelOverview>

After completing this guide, you will be able to reproduce the following example.

[Demo Source](https://demos.telerik.com/kendo-react-ui/form/basic/func/source.txt)

## Before You Begin

To follow the steps in this guide, you need to have a React project set up. If you don't have one, you can create a new React application using Vite by running the following command in your terminal:

```sh
npm create vite@latest my-app -- --template react-ts
```

This guide requires that you have **basic knowledge of React and TypeScript**, and that you have already created [**a blank React project**](https://www.telerik.com/kendo-react-ui/components/getting-started).

> tip You can accelerate your Form journey with the [KendoReact Agentic UI Generator](https://www.telerik.com/kendo-react-ui/components/ai-tools/agentic-ui-generator/getting-started) and the [Component Assistant prompts](https://www.telerik.com/kendo-react-ui/components/ai-tools/agentic-ui-generator/prompt-library#component-assistant).

## Install the Component

The KendoReact Form package is distributed via [npm](https://www.npmjs.com/package/@progress/kendo-react-form) and can be installed using the npm package manager.

To install the Form package along with its [dependencies](https://www.telerik.com/kendo-react-ui-develop/components/form/get-started#kendoreact-form-dependencies) and Kendo theme, run the following command in the root folder of your React project:

```sh
npm i @progress/kendo-react-form @progress/kendo-theme-meridian
```

The example also uses the Labels, Inputs, and Buttons packages. Install them if they are not already in your project:

```sh
npm i @progress/kendo-react-labels @progress/kendo-react-inputs @progress/kendo-react-buttons
```

Import the CSS file from the package in `src/App.tsx`. Add this import before your existing `App.css` import:

```jsx
import '@progress/kendo-theme-meridian/dist/all.css';
```

To style the Form, use the [Meridian theme](https://www.telerik.com/design-system/docs/themes/kendo-themes/meridian/), which is one of the [themes](https://www.telerik.com/kendo-react-ui-develop/components/styling) for KendoReact.

> tip Are you looking for guidance around how to create visually appealing and consistent user interfaces with Telerik UI components? Check out the [Progress Design System](https://www.telerik.com/design-system/docs/).

## Use the Component

In the `src/App.tsx` file of your React project, import the Form, Field, and FormElement components from the Form package, and then the Error and Input components:

* The FormElement is a small wrapper for an HTML form element that automatically attaches the Form component's `onSubmit` event and provides the handy `render` prop as well as some useful CSS classes.
* The Field component is needed to render inputs.
* The Error component from the Labels package allows you to display error text messages.
* The Input component from the Inputs package allows users to submit values.

```tsx
import { Form, Field, FormElement, type FieldRenderProps } from '@progress/kendo-react-form';
import { Error } from '@progress/kendo-react-labels';
import { Input } from '@progress/kendo-react-inputs';
import { Button } from '@progress/kendo-react-buttons';
```

1. Create an `emailRegex` in order to validate the user's email address and an `emailInput` component that will render the input field.

   ```tsx
   const emailRegex = /\S+@\S+\.\S+/;
   const emailValidator = (value: string) => emailRegex.test(value) ? '' : 'Please enter a valid email.';
   const EmailInput = (fieldRenderProps: FieldRenderProps) => {
       const { validationMessage, visited, ...others } = fieldRenderProps;
       return (
           <div>
               <Input {...others} />
               {visited && validationMessage && <Error>{validationMessage}</Error>}
           </div>
       );
   };
   ```

2. Handle the `onSubmit` event by creating a handler function.

   ```tsx
   const handleSubmit = (dataItem: Record<string, unknown>) => alert(JSON.stringify(dataItem, null, 2));
   ```

3. Add the component's markup to the `src/App.tsx` file in your project and set the Form's name, component, label, and validator. Optionally, set the `maxWidth`.

   ```jsx
   return (
       <Form
           onSubmit={handleSubmit}
           render={(formRenderProps) => (
               <FormElement style={{ maxWidth: 650 }}>
                   <fieldset className={'k-form-fieldset'}>
                       <legend className={'k-form-legend'}>Please fill in the fields:</legend>
                       <div className="mb-3">
                           <Field name={'firstName'} component={Input} label={'First name'} />
                       </div>
                       <div className="mb-3">
                           <Field name={'lastName'} component={Input} label={'Last name'} />
                       </div>
                       <div className="mb-3">
                           <Field
                               name={'email'}
                               type={'email'}
                               component={EmailInput}
                               label={'Email'}
                               validator={emailValidator}
                           />
                       </div>
                   </fieldset>
                   <div className="k-form-buttons">
                       <Button type={'submit'} disabled={!formRenderProps.allowSubmit}>
                           Submit
                       </Button>
                   </div>
               </FormElement>
           )}
       />
   );
   ```

4. Build and run the application by typing the following command in the root folder of your project.

   ```sh
   npm run dev
   ```

5. Navigate to [http://localhost:5173](http://localhost:5173/) to see the KendoReact Form component on the page.

## KendoReact Form Dependencies

The Form package requires you to install the following [peer dependencies](https://nodejs.org/en/blog/npm/peer-dependencies/) in your application:

| Package Name                 | Description                                                      |
| ---------------------------- | ---------------------------------------------------------------- |
| react 18.x or 19.x           | Contains the functionality necessary to define React components. |
| react-dom                    | Contains the React renderer for the web.                         |
| @progress/kendo-licensing    | Contains the internal infrastructure related to licensing.       |
| @progress/kendo-react-common | Contains common utilities for the KendoReact UI components.      |

## Activating Your License Key

**Important**: The KendoReact Form is a premium component that requires a license key file to be installed in your project:

* **Trial usage**: [Start a free trial](https://www.telerik.com/try/kendo-react-ui) and download a trial license key file
* **Commercial usage**: [Purchase a license](https://www.telerik.com/kendo-react-ui/pricing) and download a commercial license key file

Without a valid license key file, the component will display licensing warnings and watermarks.

Follow the instructions on the KendoReact [My License page](https://www.telerik.com/kendo-react-ui-develop/components/my-license) to download and install your license key file. You can skip this step if your application already contains a KendoReact license file.

## Next Steps

* [Form Design Guidelines](https://www.telerik.com/kendo-react-ui-develop/components/form/guidelines-with-examples)
* [Labels](https://www.telerik.com/kendo-react-ui-develop/components/form/labels)
* [Multi-Step Form](https://www.telerik.com/kendo-react-ui-develop/components/form/wizard/validation)
* [Layout](https://www.telerik.com/kendo-react-ui-develop/components/form/layout)
* [Responsive Design](https://www.telerik.com/kendo-react-ui-develop/components/form/responsive)
* [Appearance](https://www.telerik.com/kendo-react-ui-develop/components/form/appearance)
* [Validation](https://www.telerik.com/kendo-react-ui-develop/components/form/validation)

## Learning Resources

* [Getting Started with KendoReact](https://www.telerik.com/kendo-react-ui-develop/components/getting-started)
* [React Form Overview](https://www.telerik.com/kendo-react-ui-develop/components/form)
* [API Reference of the KendoReact Form](https://www.telerik.com/kendo-react-ui-develop/components/form/api)
* [KendoReact Free vs. Premium](https://www.telerik.com/kendo-react-ui-develop/components/getting-started/free-vs-premium)
* [Video Courses](https://www.telerik.com/kendo-react-ui-develop/components/getting-started/video-onboarding)
* [Before You Start: All Things React (Telerik Blog Post)](https://www.telerik.com/blogs/all-things-react)
* [Knowledge Base](https://www.telerik.com/kendo-react-ui/components/knowledge-base)
* [Explore the Finance Portfolio Sample Application](https://www.telerik.com/kendo-react-ui/components/sample-applications/finance-application/)
* [Explore the Coffee Warehouse Sample Application](https://www.telerik.com/kendo-react-ui/components/sample-applications/react-coffee-warehouse-dashboard/)
* [Explore the GitHub Issues Grid Sample Application](https://www.telerik.com/kendo-react-ui/components/sample-applications/issues-grid/)
