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 = [] }