Parcourir la source

fix Alert instance form not init bug (#9258)

Devosend il y a 3 ans
Parent
commit
fa56751a56

+ 12 - 0
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
   }
 }

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