diff libervia/web/pages/_browser/dialog.py @ 1589:7228fc3c4744

browser (dialog): be sure to remove dialog on `OK` and `Cancel` click + avoid side effects
author Goffi <goffi@goffi.org>
date Sun, 10 Dec 2023 11:00:44 +0100
parents e47c24204449
children 0a4433a343a3
line wrap: on
line diff
--- a/libervia/web/pages/_browser/dialog.py	Sun Dec 10 10:59:25 2023 +0100
+++ b/libervia/web/pages/_browser/dialog.py	Sun Dec 10 11:00:44 2023 +0100
@@ -19,6 +19,7 @@
         assert ok_color in ("success", "danger")
         self.ok_color = ok_color
         self.cancel_label = cancel_label
+        self._notif_elt = None
         self.reset()
 
     def reset(self):
@@ -26,7 +27,9 @@
         self._ok_cb = None
         self._cancel_cb = None
         self._reject_cb = None
-        self._notif_elt = None
+        if self._notif_elt is not None:
+            self._notif_elt.remove()
+            self._notif_elt = None
 
     def _default_cancel_cb(self, evt, notif_elt):
         notif_elt.remove()
@@ -40,6 +43,7 @@
             log.warning("calling cancel on an unshown dialog")
         else:
             self._notif_elt.remove()
+            self._notif_elt = None
             if self._reject_cb is not None:
                 self._reject_cb(CancelError)
             else:
@@ -47,11 +51,15 @@
         self.reset()
 
     def on_ok_click(self, evt):
+        evt.preventDefault()
+        evt.stopPropagation()
         assert self._ok_cb is not None
         self._ok_cb(evt, self._notif_elt)
         self.reset()
 
     def on_cancel_click(self, evt) -> None:
+        evt.preventDefault()
+        evt.stopPropagation()
         assert self._cancel_cb is not None
         self._cancel_cb(evt, self._notif_elt)
         self.reset()