diff --git a/components/form/Form.tsx b/components/form/Form.tsx index 7716f889d..36b00e835 100755 --- a/components/form/Form.tsx +++ b/components/form/Form.tsx @@ -151,7 +151,7 @@ const Form = defineComponent({ delete fields[eventKey]; }; - const getFieldsByNameList = (nameList: NamePath[]) => { + const getFieldsByNameList = (nameList: NamePath | NamePath[]) => { const provideNameList = !!nameList; const namePathList = provideNameList ? toArray(nameList).map(getNamePath) : []; if (!provideNameList) { @@ -163,17 +163,17 @@ const Form = defineComponent({ ); } }; - const resetFields = (name?: NamePath) => { + const resetFields = (name?: NamePath | NamePath[]) => { if (!props.model) { warning(false, 'Form', 'model is required for resetFields to work.'); return; } - getFieldsByNameList(name ? [name] : undefined).forEach(field => { + getFieldsByNameList(name).forEach(field => { field.resetField(); }); }; - const clearValidate = (name?: NamePath) => { - getFieldsByNameList(name ? [name] : undefined).forEach(field => { + const clearValidate = (name?: NamePath | NamePath[]) => { + getFieldsByNameList(name).forEach(field => { field.clearValidate(); }); }; diff --git a/components/form/index.en-US.md b/components/form/index.en-US.md index 57000e7dc..f40a1cedc 100644 --- a/components/form/index.en-US.md +++ b/components/form/index.en-US.md @@ -57,14 +57,18 @@ A form consists of one or more form fields whose type includes input, textarea, ### Methods -| Method | Description | Parameters | | +| Method | Description | Parameters | Version | | --- | --- | --- | --- | -| 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) | | -| resetFields | reset all the fields and remove validation result | — | | +| 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 | | +| resetFields | reset all the fields and remove validation result | (nameList?: [NamePath](#NamePath)\[]) => void | | | scrollToField | Scroll to field position | (name: [NamePath](#NamePath), options: \[[ScrollOptions](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options)]) => void | | | validate | Validate fields, it is same as validateFields | (nameList?: [NamePath](#NamePath)\[]) => Promise | | | validateFields | Validate fields | (nameList?: [NamePath](#NamePath)\[]) => Promise | | +#### NamePath + +`string | number | (string | number)[]` + ### Form.Item | Property | Description | Type | Default Value | Version | diff --git a/components/form/index.zh-CN.md b/components/form/index.zh-CN.md index b5ce60db7..d2d3ec8ba 100644 --- a/components/form/index.zh-CN.md +++ b/components/form/index.zh-CN.md @@ -58,13 +58,17 @@ cover: https://gw.alipayobjects.com/zos/alicdn/ORmcdeaoO/Form.svg ### 方法 -| 方法名 | 说明 | 参数 | | | -| --- | --- | --- | --- | --- | -| clearValidate | 移除表单项的校验结果。传入待移除的表单项的 name 属性或者 name 组成的数组,如不传则移除整个表单的校验结果 | Function(name: array \| string) | | | -| resetFields | 对整个表单进行重置,将所有字段值重置为初始值并移除校验结果 | — | | | -| scrollToField | 滚动到对应字段位置 | (name: [NamePath](#NamePath), options: \[[ScrollOptions](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options)]) => void | | | -| validate | 触发表单验证, 同 validateFields | (nameList?: [NamePath](#NamePath)\[]) => Promise | | | -| validateFields | 触发表单验证 | (nameList?: [NamePath](#NamePath)\[]) => Promise | | | +| 方法名 | 说明 | 参数 | 版本 | +| --- | --- | --- | --- | +| clearValidate | 移除表单项的校验结果。传入待移除的表单项的 name 属性或者 name 组成的数组,如不传则移除整个表单的校验结果 | (nameList?: [NamePath](#NamePath)\[]) => void | | +| resetFields | 对整个表单进行重置,将所有字段值重置为初始值并移除校验结果 | (nameList?: [NamePath](#NamePath)\[]) => void | | +| scrollToField | 滚动到对应字段位置 | (name: [NamePath](#NamePath), options: \[[ScrollOptions](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options)]) => void | | +| validate | 触发表单验证, 同 validateFields | (nameList?: [NamePath](#NamePath)\[]) => Promise | | +| validateFields | 触发表单验证 | (nameList?: [NamePath](#NamePath)\[]) => Promise | | + +#### NamePath + +`string | number | (string | number)[]` ### Form.Item