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 KendoReact Field component and FieldRenderProps interface.

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 } from '@progress/kendo-react-form';
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 &&
          (<div className={"k-required"}>{validationMessage}</div>)
      }
    </div>
  );
};
const App = () => {
    const handleSubmit = (dataItem) => alert(JSON.stringify(dataItem, null, 2));
    return (
        <Form
            onSubmit={handleSubmit}
            render={(formRenderProps) => (
                <form onSubmit={formRenderProps.onSubmit} className={'k-form'}>
                    <fieldset>
                        <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>
                    <button
                        type={'submit'}
                        className="k-button"
                        disabled={!formRenderProps.allowSubmit}
                    >
                        Submit
                    </button>
                </form>
            )}
        />
    );
};
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');

Dependencies

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

  • react 16.8.2*
  • react-dom
 /