React Button - Validate and Submit an HTML Form
Commonly, editors nested into an HTML form are supposed to be validated on the client and then submitted to the server. The Button UI component supports this scenario out of the box. Place the Button on the HTML form and set the useSubmitBehavior property to true.
- import React from 'react';
- import { Button } from 'devextreme-react/button';
- import { TextBox } from 'devextreme-react/text-box';
- import { Validator, RequiredRule } from 'devextreme-react/validator';
- class App extends React.Component {
- render() {
- return (
- <form action="/Login" method="post">
- <TextBox name="Login">
- <Validator>
- <RequiredRule />
- </Validator>
- </TextBox>
- <TextBox name="Password" mode="password">
- <Validator>
- <RequiredRule />
- </Validator>
- </TextBox>
- <Button
- text="Submit"
- type="success"
- useSubmitBehavior={true}
- />
- </form>
- );
- }
- }
- export default App;
Note that the name property of the TextBox UI components in the previous code specifies the name attribute of the underlying <input>
element.
DevExtreme editors may belong to different validation groups. To specify which group the Button must validate, use the validationGroup property. If you do not set this property, the Button validates all editors whose validation group is not specified.
See Also
If you have technical questions, please create a support ticket in the DevExpress Support Center.