소스 검색

Merge branch 'hotfix/V8-7511-le-formulaire-nest-plus-dirty-ap'

Olivier Massot 5 달 전
부모
커밋
c285fd7c1a
1개의 변경된 파일11개의 추가작업 그리고 3개의 파일을 삭제
  1. 11 3
      components/Ui/Form.vue

+ 11 - 3
components/Ui/Form.vue

@@ -387,9 +387,17 @@ const validate = async function () {
 }
 
 // #### Gestion de l'état dirty
-watch(props.modelValue, async (newEntity, oldEntity) => {
-  setIsDirty(true)
-})
+watch(
+  // /!\ Important de passer par un getter de l'objet (le `() => ({ ...props.modelValue })`),
+  //     car on perd la réactivité de celui-ci quand on soumet le formulaire
+  //     (et donc le watcher cesse de fonctionner)
+  () => ({ ...props.modelValue }),
+  (newEntity, oldEntity) => {
+    if (JSON.stringify(newEntity) !== JSON.stringify(oldEntity)) {
+      setIsDirty(true)
+    }
+  },
+)
 
 /**
  * Handle events if the form is dirty to prevent submission