Skip to content

Commit c6f6922

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat-v3.3
2 parents c1a1b93 + 03c4117 commit c6f6922

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

components/_util/hooks/useConfigInject.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { computed, inject } from 'vue';
44
import type { ConfigProviderProps, CSPConfig, Direction, SizeType } from '../../config-provider';
55
import { defaultConfigProvider } from '../../config-provider';
66
import type { VueNode } from '../type';
7+
import type { ValidateMessages } from '../../form/interface';
78

89
export default (
910
name: string,
@@ -20,6 +21,7 @@ export default (
2021
form?: ComputedRef<{
2122
requiredMark?: RequiredMark;
2223
colon?: boolean;
24+
validateMessages?: ValidateMessages;
2325
}>;
2426
autoInsertSpaceInButton: ComputedRef<boolean>;
2527
renderEmpty?: ComputedRef<(componentName?: string) => VueNode>;

components/form/Form.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ const Form = defineComponent({
130130
const validateMessages = computed(() => {
131131
return {
132132
...defaultValidateMessages,
133+
...contextForm.value?.validateMessages,
133134
...props.validateMessages,
134135
};
135136
});
@@ -150,7 +151,7 @@ const Form = defineComponent({
150151
delete fields[eventKey];
151152
};
152153

153-
const getFieldsByNameList = (nameList: NamePath[]) => {
154+
const getFieldsByNameList = (nameList: NamePath | NamePath[]) => {
154155
const provideNameList = !!nameList;
155156
const namePathList = provideNameList ? toArray(nameList).map(getNamePath) : [];
156157
if (!provideNameList) {
@@ -162,17 +163,17 @@ const Form = defineComponent({
162163
);
163164
}
164165
};
165-
const resetFields = (name?: NamePath) => {
166+
const resetFields = (name?: NamePath | NamePath[]) => {
166167
if (!props.model) {
167168
warning(false, 'Form', 'model is required for resetFields to work.');
168169
return;
169170
}
170-
getFieldsByNameList(name ? [name] : undefined).forEach(field => {
171+
getFieldsByNameList(name).forEach(field => {
171172
field.resetField();
172173
});
173174
};
174-
const clearValidate = (name?: NamePath) => {
175-
getFieldsByNameList(name ? [name] : undefined).forEach(field => {
175+
const clearValidate = (name?: NamePath | NamePath[]) => {
176+
getFieldsByNameList(name).forEach(field => {
176177
field.clearValidate();
177178
});
178179
};

components/form/index.en-US.md

Lines changed: 7 additions & 3 deletions
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

Lines changed: 11 additions & 7 deletions
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

components/select/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,18 @@ const Select = defineComponent({
106106

107107
return mode;
108108
});
109-
const { prefixCls, direction, configProvider, getPrefixCls } = useConfigInject('select', props);
109+
const { prefixCls, direction, configProvider, size, getPrefixCls } = useConfigInject(
110+
'select',
111+
props,
112+
);
110113
const rootPrefixCls = computed(() => getPrefixCls());
111114
const transitionName = computed(() =>
112115
getTransitionName(rootPrefixCls.value, 'slide-up', props.transitionName),
113116
);
114117
const mergedClassName = computed(() =>
115118
classNames({
116-
[`${prefixCls.value}-lg`]: props.size === 'large',
117-
[`${prefixCls.value}-sm`]: props.size === 'small',
119+
[`${prefixCls.value}-lg`]: size.value === 'large',
120+
[`${prefixCls.value}-sm`]: size.value === 'small',
118121
[`${prefixCls.value}-rtl`]: direction.value === 'rtl',
119122
[`${prefixCls.value}-borderless`]: !props.bordered,
120123
}),

0 commit comments

Comments
 (0)