Merge branch 'main' into next
Some checks failed
Build Docker Image / build-and-push (push) Waiting to run
Build Pro Image / build-and-push (push) Waiting to run
E2E / Build (push) Waiting to run
E2E / Core and plugins (push) Blocked by required conditions
E2E / plugin-workflow (push) Blocked by required conditions
E2E / plugin-workflow-approval (push) Blocked by required conditions
E2E / plugin-data-source-main (push) Blocked by required conditions
E2E / Comment on PR (push) Blocked by required conditions
NocoBase FrontEnd Test / frontend-test (18) (push) Has been cancelled

This commit is contained in:
Zeke Zhang 2024-07-14 13:02:34 +08:00
commit 6f788ccb4f
2 changed files with 5 additions and 3 deletions

View File

@ -151,7 +151,7 @@ export const useFormBlockContext = () => {
/**
* @internal
*/
export const useFormBlockProps = () => {
export const useFormBlockProps = (shouldClearInitialValues = false) => {
const ctx = useFormBlockContext();
const treeParentRecord = useTreeParentRecord();
useEffect(() => {
@ -169,7 +169,9 @@ export const useFormBlockProps = () => {
if (form) {
// form 字段中可能一开始就存在一些默认值(比如设置了字段默认值的模板区块)。在编辑表单中,
// 这些默认值是不需要的需要清除掉不然会导致一些问题。比如https://github.com/nocobase/nocobase/issues/4868
form.initialValues = {};
if (shouldClearInitialValues) {
form.initialValues = {};
}
form.setInitialValues(ctx.service?.data?.data);
}
}

View File

@ -10,5 +10,5 @@
import { useFormBlockProps } from '../../../../../block-provider/FormBlockProvider';
export function useEditFormBlockProps() {
return useFormBlockProps();
return useFormBlockProps(true);
}