React Form Overview
The Form Component in React is used for setting up a contact form and/or a registration page that fit in any application's requirements. You can easily provide React form validation, define form orientation, and configure or customize your desired layout as well. The React form component also exposes events that give you the opportunity to respond to user actions.
React Form Example
The following example represents IgrForm
that has some inputs, buttons and a checkbox inside.
Usage
First, you need to the install the corresponding Ignite UI for React npm package by running the following command:
npm install igniteui-react
You will then need to import the IgrForm
, its necessary CSS, and register its module, like so:
import { IgrFormModule, IgrForm } from 'igniteui-react';
import 'igniteui-webcomponents/themes/light/bootstrap.css';
IgrFormModule.register();
The simplest way to start using the IgrForm
is as follows:
Form data is collected for the following components:
When a form control is invalid, the form will not be submitted and an error message will be shown. If you want to specify that the form elements should not be validated when the form is submitted you can add the novalidate
attribute to the IgrForm
element:
<IgrForm novalidate="true"></IgrForm>
Events
The Form component raises the following events:
- Submit - Raised when the form is submitted
- Reset - Raised when the form is reset
Here is an example showing how to add an event listener for the Submit
event:
document.addEventListener('igcSubmit', function (event) {
const customEvent = event as CustomEvent<FormData>;
console.log(customEvent.detail);
});
Methods
The Form component exposes the following methods:
Method | Description |
---|---|
Submit |
Submits the form data. |
Reset |
Resets the form data. |
GetFormData |
Collects the form data and returns a single FormData object. |
reportValidity |
Returns whether the element's child controls satisfy their validation constraints. |
API References
IgrButton
IgrCheckbox
IgrForm
IgrInput
IgrRadio
Submit