Getting Started with KendoReact Form

KendoReact Form is a small and fast package for form state management with zero dependencies.

The minified and gzipped bundle of the Form is 5KB. The component integrates with all KendoReact components and, currently, is used by the built-in editor of the KendoReact Scheduler. For getting its field state, rendering custom components, and handling component events, the Form component uses the following components:

For creating form layouts the Form package provides the following components:

The Form component is part of KendoReact, a professionally built commercial UI library. To try out this component you need to sign up for a 30-day trial, which gives you access to the full KendoReact library.

Basic Usage

The following example demonstrates the Form and Field components in action.

import React from 'react';
import ReactDOM from 'react-dom';
import { Form, Field, FormElement } from '@progress/kendo-react-form';
import { Error } from '@progress/kendo-react-labels';
import { Input } from '@progress/kendo-react-inputs';

const emailRegex = new RegExp(/\S+@\S+\.\S+/);
const emailValidator = (value) => (emailRegex.test(value) ? "" : "Please enter a valid email.");
const EmailInput = (fieldRenderProps) => {
  const { validationMessage, visited, ...others } = fieldRenderProps;
  return (
    <div>
      <Input {...others} />
      {
        visited && validationMessage &&
          (<Error>{validationMessage}</Error>)
      }
    </div>
  );
};
const App = () => {
    const handleSubmit = (dataItem) => alert(JSON.stringify(dataItem, null, 2));
    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'}
                            className="k-button"
                            disabled={!formRenderProps.allowSubmit}
                        >
                            Submit
                        </button>
                    </div>
                </FormElement>
            )}
        />
    );
};
ReactDOM.render(
    <App />,
    document.querySelector('my-app')
);

Functionality and Features

Installation

  1. Download and install the package. Use Node.js v5.0.0 or later.

    npm install --save @progress/kendo-react-form
  2. Once installed, import the package module.

    // ES2015 module syntax
    import { Form, Field } from '@progress/kendo-react-form';
    // CommonJS format
    const { Form, Field } = require('@progress/kendo-react-form');
  3. You are required to install one of the Kendo UI themes to style your components. For more information on how to add the styles, refer to the article on getting started.

Dependencies

The Form package requires the following peer dependencies that have to be installed by your application:

  • react 16.8.2*
  • react-dom