Browse Source

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

Olivier Massot 5 months ago
parent
commit
c285fd7c1a
1 changed files with 11 additions and 3 deletions
  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