Skip to content

Commit def6a72

Browse files
committed
fix: form scrollToField not work form nest field, close #5404, #5407
1 parent 00dc2ad commit def6a72

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

components/form/Form.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ const Form = defineComponent({
174174
delete fields[eventKey];
175175
};
176176

177-
const getFieldsByNameList = (nameList: NamePath) => {
177+
const getFieldsByNameList = (nameList: NamePath[]) => {
178178
const provideNameList = !!nameList;
179179
const namePathList = provideNameList ? toArray(nameList).map(getNamePath) : [];
180180
if (!provideNameList) {
@@ -186,17 +186,17 @@ const Form = defineComponent({
186186
);
187187
}
188188
};
189-
const resetFields = (name: NamePath) => {
189+
const resetFields = (name?: NamePath) => {
190190
if (!props.model) {
191191
warning(false, 'Form', 'model is required for resetFields to work.');
192192
return;
193193
}
194-
getFieldsByNameList(name).forEach(field => {
194+
getFieldsByNameList(name ? [name] : undefined).forEach(field => {
195195
field.resetField();
196196
});
197197
};
198-
const clearValidate = (name: NamePath) => {
199-
getFieldsByNameList(name).forEach(field => {
198+
const clearValidate = (name?: NamePath) => {
199+
getFieldsByNameList(name ? [name] : undefined).forEach(field => {
200200
field.clearValidate();
201201
});
202202
};
@@ -214,8 +214,8 @@ const Form = defineComponent({
214214
const validate = (...args: any[]) => {
215215
return validateField(...args);
216216
};
217-
const scrollToField = (name: NamePath, options = {}) => {
218-
const fields = getFieldsByNameList(name);
217+
const scrollToField = (name?: NamePath, options = {}) => {
218+
const fields = getFieldsByNameList(name ? [name] : undefined);
219219
if (fields.length) {
220220
const fieldId = fields[0].fieldId.value;
221221
const node = fieldId ? document.getElementById(fieldId) : null;

0 commit comments

Comments
 (0)