Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search form collapsed #1572

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/form-render/api-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ rules: [


### action
- 描述:输入控件支持配置自定义功能槽,显示在输入控件右边,通过 actions 值和 widgets 字段间映射,渲染自定义自定义功能槽。
- 描述:输入控件支持配置自定义功能槽,显示在输入控件右边,通过 action 值和 widgets 字段间映射,渲染自定义自定义功能槽。
- 类型
```js
actions: 'toolWidget' | { widget: 'toolWidget' } // toolWidget 通过 widgets 透传
action: 'toolWidget' | { widget: 'toolWidget' } // toolWidget 通过 widgets 透传
```

## 三、嵌套控件配置项
Expand Down
6 changes: 6 additions & 0 deletions packages/form-render/src/derivative/SearchForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ const SearchForm: <RecordType extends object = any>(props: SearchProps<RecordTyp
initMount();
});

useUpdateEffect(() => {
if (isExpand) {
initMount();
}
}, [isExpand]);

useMount(() => {
if (!collapsed) {
return;
Expand Down
13 changes: 7 additions & 6 deletions packages/form-render/src/models/useForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ const useForm = () => {

const setStoreData = (data: any) => {
const { setState } = storeRef.current;

if (!setState) {
setTimeout(() => {
setState({ schema: schemaRef.current, flattenSchema: flattenSchemaRef.current });
Expand Down Expand Up @@ -195,7 +195,7 @@ const useForm = () => {
form.setFieldValue(name, value);
}
} catch (error) {

}
}

Expand Down Expand Up @@ -324,13 +324,14 @@ const useForm = () => {
}

// 触发表单验证
xform.validateFields = (pathList?: string[]) => {
xform.validateFields = (pathList?: string[], config?: object) => {
const nameList = (pathList || []).map(path => getFieldName(path));
if (nameList.length > 0) {
return validateFields(nameList);
return validateFields(nameList, config);
}
return validateFields();
}
};


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

export default useForm;
export default useForm;
26 changes: 13 additions & 13 deletions packages/form-render/src/render-core/FieldItem/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import {
FieldWrapperStatus
} from './field';

import {
getParamValue,
import {
getParamValue,
getFieldProps,
getPath,
getLabel,
Expand All @@ -39,7 +39,7 @@ export default (props: any) => {
const upperCtx: any = useContext(UpperContext);

const { form, widgets, methods, globalProps } = configCtx;
const {
const {
reserveLabel,
hidden,
properties,
Expand All @@ -52,7 +52,7 @@ export default (props: any) => {
} = schema;

const getValueFromKey = getParamValue(formCtx, upperCtx, schema);

const widgetName = getWidgetName(schema);
let Widget = getWidget(widgetName, widgets);

Expand Down Expand Up @@ -82,7 +82,7 @@ export default (props: any) => {
}

if (schema.type === 'void') {
return (
return (
<Col span={24}>
<Widget {...fieldProps } />
</Col>
Expand Down Expand Up @@ -180,7 +180,7 @@ export default (props: any) => {
label = null;
if (displayType === 'row') {
label = 'fr-hide-label';
}
}
}

const initialValue = schema.default ?? schema.defaultValue;
Expand All @@ -205,20 +205,20 @@ export default (props: any) => {
validateTrigger={ validateTrigger ?? (fieldRef?.current?.validator ? 'onSubmit' : 'onChange') }
>
{fieldProps.onStatusChange ? (
<FieldWrapperStatus
<FieldWrapperStatus
Field={Widget}
fieldProps={fieldProps}
maxWidth={maxWidth}
initialValue={initialValue}
acitonRender={() => action}
acitonRender={action ? () => action : undefined}
/>
) : (
<FieldWrapper
Field={Widget}
fieldProps={fieldProps}
maxWidth={maxWidth}
initialValue={initialValue}
acitonRender={() => action}
acitonRender={action ? () => action : undefined}
/>
)}
</Form.Item>
Expand All @@ -227,7 +227,7 @@ export default (props: any) => {
if (inlineSelf) {
if (noStyle) {
return (
<div
<div
className={classnames('fr-inline-field', { 'fr-field-visibility': !visible, [schema.className] : !! schema.className })}
>
{formItem}
Expand All @@ -238,11 +238,11 @@ export default (props: any) => {
}

return (
<Col
span={span}
<Col
span={span}
className={classnames(null, { 'fr-field-visibility': !visible })}
>
{formItem}
</Col>
);
}
}
24 changes: 13 additions & 11 deletions packages/form-render/src/widgets/listDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,6 @@ const TableList: React.FC<Props> = (props: any) => {
indexRef.current = null;
};

const hanldeConfirm = () => {
form
.validateFields()
.then(res => {
handleCloseDrawer();
})
.catch(error => {
console.log('表单校验错误', error);
});
};

const columns: any = sortProperties(Object.entries(columnSchema))
.map(([dataIndex, item]) => {
const { required, title, tooltip, width, columnHidden } = item;
Expand Down Expand Up @@ -251,6 +240,19 @@ const TableList: React.FC<Props> = (props: any) => {

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

const hanldeConfirm = () => {
const path = [...rootPath, drawerIndex]?.join('.');
form
.validateFields([path], { recursive: true })
.then(res => {
handleCloseDrawer();
})
.catch(error => {
console.log('表单校验错误', error);
});
};


return (
<div className='fr-list-drawer'>
<Table
Expand Down
Loading