React Validator - RequiredRule
import { ValidationRulesTypes } from "devextreme-react/validation-rules"
Type:
ValidationRulesTypes.RequiredRule
Use this rule type to ensure the target editor value is specified. The rule will be broken in the following cases.
- If the validated value is null, false, or undefined.
- If the specified value has a type that is not expected for the target field (e.g., a string for the DateBox UI component).
See Also
message
Type:
Default Value: 'Required'
An error message can be specified as follows:
Hard-code the message
App.js- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { TextBox } from 'devextreme-react/text-box';
- import {
- Validator,
- RequiredRule
- } from 'devextreme-react/validator';
- class App extends React.Component {
- render() {
- return (
- <TextBox>
- <Validator>
- <RequiredRule
- message="My custom message" />
- </Validator>
- </TextBox>
- );
- }
- }
- export default App;
Hide the message
App.js- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { TextBox } from 'devextreme-react/text-box';
- import {
- Validator,
- RequiredRule
- } from 'devextreme-react/validator';
- class App extends React.Component {
- render() {
- return (
- <TextBox>
- <Validator>
- <RequiredRule
- message="" />
- </Validator>
- </TextBox>
- );
- }
- }
- export default App;
Display the editor's name in the message
App.js- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import { TextBox } from 'devextreme-react/text-box';
- import {
- Validator,
- RequiredRule
- } from 'devextreme-react/validator';
- class App extends React.Component {
- render() {
- return (
- <TextBox>
- {/* The error message will be "Password is required" */}
- <Validator name="Password">
- <RequiredRule} />
- </Validator>
- </TextBox>
- );
- }
- }
- export default App;
type
Type:
Accepted Values: 'required' | 'numeric' | 'range' | 'stringLength' | 'custom' | 'compare' | 'pattern' | 'email' | 'async'
Feel free to share topic-related thoughts here.
If you have technical questions, please create a support ticket in the DevExpress Support Center.
Thank you for the feedback!
If you have technical questions, please create a support ticket in the DevExpress Support Center.