Skip to content

Commit 6528ee5

Browse files
author
昔梦
committed
fix:修复drawerlist 浮层中校验相关问题
1 parent 41c91a5 commit 6528ee5

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

packages/form-render/src/models/useForm.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const useForm = () => {
9696

9797
const setStoreData = (data: any) => {
9898
const { setState } = storeRef.current;
99-
99+
100100
if (!setState) {
101101
setTimeout(() => {
102102
setState({ schema: schemaRef.current, flattenSchema: flattenSchemaRef.current });
@@ -195,7 +195,7 @@ const useForm = () => {
195195
form.setFieldValue(name, value);
196196
}
197197
} catch (error) {
198-
198+
199199
}
200200
}
201201

@@ -324,13 +324,14 @@ const useForm = () => {
324324
}
325325

326326
// 触发表单验证
327-
xform.validateFields = (pathList?: string[]) => {
327+
xform.validateFields = (pathList?: string[], config?: object) => {
328328
const nameList = (pathList || []).map(path => getFieldName(path));
329329
if (nameList.length > 0) {
330-
return validateFields(nameList);
330+
return validateFields(nameList, config);
331331
}
332332
return validateFields();
333-
}
333+
};
334+
334335

335336
xform.getFlattenSchema = (path?: string) => {
336337
if (!path) {
@@ -356,4 +357,4 @@ const useForm = () => {
356357
return xform as FormInstance;
357358
};
358359

359-
export default useForm;
360+
export default useForm;

packages/form-render/src/widgets/listDrawer/index.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,6 @@ const TableList: React.FC<Props> = (props: any) => {
105105
indexRef.current = null;
106106
};
107107

108-
const hanldeConfirm = () => {
109-
form
110-
.validateFields()
111-
.then(res => {
112-
handleCloseDrawer();
113-
})
114-
.catch(error => {
115-
console.log('表单校验错误', error);
116-
});
117-
};
118-
119108
const columns: any = sortProperties(Object.entries(columnSchema))
120109
.map(([dataIndex, item]) => {
121110
const { required, title, tooltip, width, columnHidden } = item;
@@ -251,6 +240,19 @@ const TableList: React.FC<Props> = (props: any) => {
251240

252241
const drawerIndex = indexRef.current ?? (fields.length - 1);
253242

243+
const hanldeConfirm = () => {
244+
const path = [...rootPath, drawerIndex]?.join('.');
245+
form
246+
.validateFields([path], { recursive: true })
247+
.then(res => {
248+
handleCloseDrawer();
249+
})
250+
.catch(error => {
251+
console.log('表单校验错误', error);
252+
});
253+
};
254+
255+
254256
return (
255257
<div className='fr-list-drawer'>
256258
<Table

0 commit comments

Comments
 (0)