From fa56751a56742d372b9e1d0f55213c10c20d0c78 Mon Sep 17 00:00:00 2001 From: Devosend Date: Tue, 29 Mar 2022 17:39:04 +0800 Subject: [PATCH] fix Alert instance form not init bug (#9258) --- .../src/components/form/use-form.ts | 12 ++++++++++++ .../views/security/alarm-instance-manage/use-form.ts | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/dolphinscheduler-ui-next/src/components/form/use-form.ts b/dolphinscheduler-ui-next/src/components/form/use-form.ts index b474d521d4..2f76a11270 100644 --- a/dolphinscheduler-ui-next/src/components/form/use-form.ts +++ b/dolphinscheduler-ui-next/src/components/form/use-form.ts @@ -26,6 +26,17 @@ export function useForm() { await state.formRef.validate(...args) } + const resetValues = (initialValues: { [field: string]: any }) => { + const modelKeys = Object.keys(state.formRef.model) + for (const key of modelKeys) { + if (!Object.keys(initialValues).includes(key)) { + delete state.formRef.model[key] + } + } + + setValues(initialValues) + } + const setValues = (initialValues: { [field: string]: any }) => { for (const [key, value] of Object.entries(initialValues)) { state.formRef.model[key] = value @@ -45,6 +56,7 @@ export function useForm() { validate, setValues, getValues, + resetValues, restoreValidation } } diff --git a/dolphinscheduler-ui-next/src/views/security/alarm-instance-manage/use-form.ts b/dolphinscheduler-ui-next/src/views/security/alarm-instance-manage/use-form.ts index e8a75bfa89..1e5fc3db0e 100644 --- a/dolphinscheduler-ui-next/src/views/security/alarm-instance-manage/use-form.ts +++ b/dolphinscheduler-ui-next/src/views/security/alarm-instance-manage/use-form.ts @@ -96,7 +96,7 @@ export function useForm() { } const resetForm = () => { - state.detailFormRef.setValues({ ...initialValues }) + state.detailFormRef.resetValues({ ...initialValues }) state.json = [] }