Skip to content

Commit 699c79b

Browse files
Form: Update isRequired and RequiredRule (#8084) (#8090)
1 parent 5101ac3 commit 699c79b

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

api-reference/10 UI Components/dxForm/5 Item Types/SimpleItem/isRequired.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,29 @@ default: undefined
55
---
66
---
77
##### shortDescription
8-
Specifies whether the current form item is required.
8+
Specifies if the current form item is required.
99

1010
---
11+
When this property is enabled, Form uses [RequiredRule](/api-reference/10%20UI%20Components/dxValidator/8%20Validation%20Rules/RequiredRule '/Documentation/ApiReference/UI_Components/dxValidator/Validation_Rules/RequiredRule/') to validate the current item. The following values break **RequiredRule**:
12+
13+
- [Falsy JavaScript values](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) except `0`, `-0`, `0n`, and `NaN`.
14+
- Invalid values for the target editor (for example, a non-numeric string for the [NumberBox](/api-reference/10%20UI%20Components/dxNumberBox '/Documentation/ApiReference/UI_Components/dxNumberBox/') component).
15+
1116
[note]
1217

13-
If you specify validation rules using the [validationRules](/api-reference/10%20UI%20Components/dxForm/5%20Item%20Types/SimpleItem/validationRules.md '/Documentation/ApiReference/UI_Components/dxForm/Item_Types/SimpleItem/#validationRules') property, the **isRequired** property is ignored. In this case, use the [Require](/api-reference/10%20UI%20Components/dxValidator/8%20Validation%20Rules/RequiredRule '/Documentation/ApiReference/UI_Components/dxValidator/Validation_Rules/RequiredRule/') validation rule instead.
18+
If you specify [validationRules](/api-reference/10%20UI%20Components/dxForm/5%20Item%20Types/SimpleItem/validationRules.md '/Documentation/ApiReference/UI_Components/dxForm/Item_Types/SimpleItem/#validationRules'), Form ignores the **isRequired** property. To implement **isRequired** functionality, specify a **RequiredRule** validation rule:
1419

1520
---
1621
##### jQuery
1722

1823
<!--JavaScript-->
1924
$(function() {
20-
$("#formContainer").dxForm({
21-
// ...
25+
$('#formContainer').dxForm({
2226
items: [{
23-
// ...
2427
validationRules: [
25-
{ type: "required" }
28+
{ type: 'required' }
2629
]
27-
},
28-
// ...
29-
]
30+
}, ... ]
3031
});
3132
});
3233

@@ -40,7 +41,7 @@ If you specify validation rules using the [validationRules](/api-reference/10%20
4041
</dx-form>
4142

4243
<!--TypeScript-->
43-
import { DxFormModule } from "devextreme-angular";
44+
import { DxFormModule } from 'devextreme-angular/ui/form';
4445
// ...
4546
export class AppComponent {
4647
// ...
@@ -57,14 +58,14 @@ If you specify validation rules using the [validationRules](/api-reference/10%20
5758

5859
<!-- tab: App.vue -->
5960
<template>
60-
<DxForm ...>
61-
<DxSimpleItem ...>
62-
<DxRequiredRule .../>
61+
<DxForm ... >
62+
<DxSimpleItem ... >
63+
<DxRequiredRule ... />
6364
</DxSimpleItem>
6465
</DxForm>
6566
</template>
6667
<script>
67-
import DxForm, { DxSimpleItem, DxRequiredRule } from 'devextreme-vue/form';
68+
import { DxForm, DxSimpleItem, DxRequiredRule } from 'devextreme-vue/form';
6869

6970
export default {
7071
components: {
@@ -79,9 +80,9 @@ If you specify validation rules using the [validationRules](/api-reference/10%20
7980

8081
<!-- tab: App.js -->
8182
import React from 'react';
82-
import Form, { SimpleItem, RequiredRule } from 'devextreme-react/form';
83+
import { Form, SimpleItem, RequiredRule } from 'devextreme-react/form';
8384

84-
const App = () => {
85+
function App () {
8586
return (
8687
<Form ...>
8788
<SimpleItem ...>

api-reference/10 UI Components/dxValidator/8 Validation Rules/RequiredRule/RequiredRule.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ generateTypeLink:
77
---
88
---
99
##### shortDescription
10-
A validation rule that demands that a validated field has a value.
10+
A validation rule that rejects empty and invalid values.
1111

1212
---
13-
Use this rule type to ensure the target editor value is specified. The rule will be broken in the following cases.
13+
The following values break **RequiredRule**:
1414

15-
- If the validated value is **null**, **false**, or **undefined**.
16-
- If the specified value has a type that is not expected for the target field (e.g., a string for the [DateBox](/api-reference/10%20UI%20Components/dxDateBox '/Documentation/ApiReference/UI_Components/dxDateBox/') UI component).
15+
- [Falsy JavaScript values](https://developer.mozilla.org/en-US/docs/Glossary/Falsy) except `0`, `-0`, `0n`, and `NaN`.
16+
- Invalid values for the target editor (for example, a non-numeric string for the [NumberBox](/api-reference/10%20UI%20Components/dxNumberBox '/Documentation/ApiReference/UI_Components/dxNumberBox/') component).
1717

1818
#include btn-open-demo with {
1919
href: "https://js.devexpress.com/Demos/WidgetsGallery/Demo/Validation/Overview/"

0 commit comments

Comments
 (0)