From 40be639b63becf119841bd54cb82759918f41375 Mon Sep 17 00:00:00 2001 From: bqy_fe <1743369777@qq.com> Date: Thu, 12 May 2022 09:50:12 +0800 Subject: [PATCH 1/3] feat(select): support global size (#5590) --- components/select/index.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/components/select/index.tsx b/components/select/index.tsx index 99e450f31..4275c5413 100644 --- a/components/select/index.tsx +++ b/components/select/index.tsx @@ -106,15 +106,18 @@ const Select = defineComponent({ return mode; }); - const { prefixCls, direction, configProvider, getPrefixCls } = useConfigInject('select', props); + const { prefixCls, direction, configProvider, size, getPrefixCls } = useConfigInject( + 'select', + props, + ); const rootPrefixCls = computed(() => getPrefixCls()); const transitionName = computed(() => getTransitionName(rootPrefixCls.value, 'slide-up', props.transitionName), ); const mergedClassName = computed(() => classNames({ - [`${prefixCls.value}-lg`]: props.size === 'large', - [`${prefixCls.value}-sm`]: props.size === 'small', + [`${prefixCls.value}-lg`]: size.value === 'large', + [`${prefixCls.value}-sm`]: size.value === 'small', [`${prefixCls.value}-rtl`]: direction.value === 'rtl', [`${prefixCls.value}-borderless`]: !props.bordered, }), From 7a9111032669b0393702b6866f65be6f6d00abd8 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Sun, 15 May 2022 10:14:11 +0800 Subject: [PATCH 2/3] fix: global validateMessages no work, close #5599 --- components/_util/hooks/useConfigInject.ts | 2 ++ components/form/Form.tsx | 1 + 2 files changed, 3 insertions(+) diff --git a/components/_util/hooks/useConfigInject.ts b/components/_util/hooks/useConfigInject.ts index 079ac95b3..be02d9241 100644 --- a/components/_util/hooks/useConfigInject.ts +++ b/components/_util/hooks/useConfigInject.ts @@ -4,6 +4,7 @@ import { computed, inject } from 'vue'; import type { ConfigProviderProps, CSPConfig, Direction, SizeType } from '../../config-provider'; import { defaultConfigProvider } from '../../config-provider'; import type { VueNode } from '../type'; +import type { ValidateMessages } from '../../form/interface'; export default ( name: string, @@ -20,6 +21,7 @@ export default ( form?: ComputedRef<{ requiredMark?: RequiredMark; colon?: boolean; + validateMessages?: ValidateMessages; }>; autoInsertSpaceInButton: ComputedRef; renderEmpty?: ComputedRef<(componentName?: string) => VueNode>; diff --git a/components/form/Form.tsx b/components/form/Form.tsx index 1f6ac45ee..7716f889d 100755 --- a/components/form/Form.tsx +++ b/components/form/Form.tsx @@ -130,6 +130,7 @@ const Form = defineComponent({ const validateMessages = computed(() => { return { ...defaultValidateMessages, + ...contextForm.value?.validateMessages, ...props.validateMessages, }; }); From 03c41177a31f1c28ef36502bfd29dc05fdf1bb41 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Thu, 19 May 2022 17:13:06 +0800 Subject: [PATCH 3/3] fix: form clearValidate & resetValidate support array, close #5619 --- components/form/Form.tsx | 10 +++++----- components/form/index.en-US.md | 10 +++++++--- components/form/index.zh-CN.md | 18 +++++++++++------- 3 files changed, 23 insertions(+), 15 deletions(-) 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