Skip to content

Commit 03c4117

Browse files
committed
fix: form clearValidate & resetValidate support array, close #5619
1 parent 7a91110 commit 03c4117

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

components/form/Form.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ const Form = defineComponent({
151151
delete fields[eventKey];
152152
};
153153

154-
const getFieldsByNameList = (nameList: NamePath[]) => {
154+
const getFieldsByNameList = (nameList: NamePath | NamePath[]) => {
155155
const provideNameList = !!nameList;
156156
const namePathList = provideNameList ? toArray(nameList).map(getNamePath) : [];
157157
if (!provideNameList) {
@@ -163,17 +163,17 @@ const Form = defineComponent({
163163
);
164164
}
165165
};
166-
const resetFields = (name?: NamePath) => {
166+
const resetFields = (name?: NamePath | NamePath[]) => {
167167
if (!props.model) {
168168
warning(false, 'Form', 'model is required for resetFields to work.');
169169
return;
170170
}
171-
getFieldsByNameList(name ? [name] : undefined).forEach(field => {
171+
getFieldsByNameList(name).forEach(field => {
172172
field.resetField();
173173
});
174174
};
175-
const clearValidate = (name?: NamePath) => {
176-
getFieldsByNameList(name ? [name] : undefined).forEach(field => {
175+
const clearValidate = (name?: NamePath | NamePath[]) => {
176+
getFieldsByNameList(name).forEach(field => {
177177
field.clearValidate();
178178
});
179179
};

components/form/index.en-US.md

+7-3
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,18 @@ A form consists of one or more form fields whose type includes input, textarea,
5757

5858
### Methods
5959

60-
| Method | Description | Parameters | |
60+
| Method | Description | Parameters | Version |
6161
| --- | --- | --- | --- |
62-
| clearValidate | clear validation message for certain fields. The parameter is name or an array of names of the form items whose validation messages will be removed. When omitted, all fields' validation messages will be cleared | Function(props: string \| array) | |
63-
| resetFields | reset all the fields and remove validation result | | |
62+
| clearValidate | clear validation message for certain fields. The parameter is name or an array of names of the form items whose validation messages will be removed. When omitted, all fields' validation messages will be cleared | (nameList?: [NamePath](#NamePath)\[]) => void | |
63+
| resetFields | reset all the fields and remove validation result | (nameList?: [NamePath](#NamePath)\[]) => void | |
6464
| scrollToField | Scroll to field position | (name: [NamePath](#NamePath), options: \[[ScrollOptions](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options)]) => void | |
6565
| validate | Validate fields, it is same as validateFields | (nameList?: [NamePath](#NamePath)\[]) => Promise | |
6666
| validateFields | Validate fields | (nameList?: [NamePath](#NamePath)\[]) => Promise | |
6767

68+
#### NamePath
69+
70+
`string | number | (string | number)[]`
71+
6872
### Form.Item
6973

7074
| Property | Description | Type | Default Value | Version |

components/form/index.zh-CN.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,17 @@ cover: https://gw.alipayobjects.com/zos/alicdn/ORmcdeaoO/Form.svg
5858

5959
### 方法
6060

61-
| 方法名 | 说明 | 参数 | | |
62-
| --- | --- | --- | --- | --- |
63-
| clearValidate | 移除表单项的校验结果。传入待移除的表单项的 name 属性或者 name 组成的数组,如不传则移除整个表单的校验结果 | Function(name: array \| string) | | |
64-
| resetFields | 对整个表单进行重置,将所有字段值重置为初始值并移除校验结果 || | |
65-
| scrollToField | 滚动到对应字段位置 | (name: [NamePath](#NamePath), options: \[[ScrollOptions](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options)]) => void | | |
66-
| validate | 触发表单验证, 同 validateFields | (nameList?: [NamePath](#NamePath)\[]) => Promise | | |
67-
| validateFields | 触发表单验证 | (nameList?: [NamePath](#NamePath)\[]) => Promise | | |
61+
| 方法名 | 说明 | 参数 | 版本 |
62+
| --- | --- | --- | --- |
63+
| clearValidate | 移除表单项的校验结果。传入待移除的表单项的 name 属性或者 name 组成的数组,如不传则移除整个表单的校验结果 | (nameList?: [NamePath](#NamePath)\[]) => void | |
64+
| resetFields | 对整个表单进行重置,将所有字段值重置为初始值并移除校验结果 | (nameList?: [NamePath](#NamePath)\[]) => void | |
65+
| scrollToField | 滚动到对应字段位置 | (name: [NamePath](#NamePath), options: \[[ScrollOptions](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options)]) => void | |
66+
| validate | 触发表单验证, 同 validateFields | (nameList?: [NamePath](#NamePath)\[]) => Promise | |
67+
| validateFields | 触发表单验证 | (nameList?: [NamePath](#NamePath)\[]) => Promise | |
68+
69+
#### NamePath
70+
71+
`string | number | (string | number)[]`
6872

6973
### Form.Item
7074

0 commit comments

Comments
 (0)