From 9594157a2db9037526efeb2153a200ed08b88fc4 Mon Sep 17 00:00:00 2001 From: formsdev <136701234+formsdev@users.noreply.github.com> Date: Thu, 4 Jan 2024 21:35:55 +0530 Subject: [PATCH] Dirty form handling - nuxt migration (#272) --- client/pages/forms/create/index.vue | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/client/pages/forms/create/index.vue b/client/pages/forms/create/index.vue index fa72a27..c8a8125 100644 --- a/client/pages/forms/create/index.vue +++ b/client/pages/forms/create/index.vue @@ -27,22 +27,23 @@ import FormEditor from "~/components/open/forms/components/FormEditor.vue" import CreateFormBaseModal from '../../../components/pages/forms/create/CreateFormBaseModal.vue' import {fetchTemplate} from "~/stores/templates.js" import {hash} from "~/lib/utils.js" +import {onBeforeRouteLeave} from 'vue-router' definePageMeta({ middleware: "auth" }) -// metaTitle: 'Create a new Form', +const metaTitle = 'Create a new Form' -// beforeRouteLeave (to, from, next) { -// if (this.isDirty()) { -// return useAlert().confirm('Changes you made may not be saved. Are you sure want to leave?', () => { -// window.onbeforeunload = null -// next() -// }, () => {}) -// } -// next() -// }, +onBeforeRouteLeave((to, from, next) => { + if (isDirty()) { + return useAlert().confirm('Changes you made may not be saved. Are you sure want to leave?', () => { + window.onbeforeunload = null + next() + }, () => {}) + } + next() +}) const route = useRoute() const authStore = useAuthStore() @@ -78,9 +79,10 @@ watch(() => workspace, () => { onMounted(() => { if (process.client) { - // window.onbeforeunload = () => { - if (isDirty()) { - return false + window.onbeforeunload = () => { + if (isDirty()) { + return false + } } }