Dirty form handling - nuxt migration (#272)

This commit is contained in:
formsdev
2024-01-04 21:35:55 +05:30
committed by GitHub
parent 33458f25f4
commit 9594157a2d

View File

@@ -27,22 +27,23 @@ import FormEditor from "~/components/open/forms/components/FormEditor.vue"
import CreateFormBaseModal from '../../../components/pages/forms/create/CreateFormBaseModal.vue' import CreateFormBaseModal from '../../../components/pages/forms/create/CreateFormBaseModal.vue'
import {fetchTemplate} from "~/stores/templates.js" import {fetchTemplate} from "~/stores/templates.js"
import {hash} from "~/lib/utils.js" import {hash} from "~/lib/utils.js"
import {onBeforeRouteLeave} from 'vue-router'
definePageMeta({ definePageMeta({
middleware: "auth" middleware: "auth"
}) })
// metaTitle: 'Create a new Form', const metaTitle = 'Create a new Form'
// beforeRouteLeave (to, from, next) { onBeforeRouteLeave((to, from, next) => {
// if (this.isDirty()) { if (isDirty()) {
// return useAlert().confirm('Changes you made may not be saved. Are you sure want to leave?', () => { return useAlert().confirm('Changes you made may not be saved. Are you sure want to leave?', () => {
// window.onbeforeunload = null window.onbeforeunload = null
// next() next()
// }, () => {}) }, () => {})
// } }
// next() next()
// }, })
const route = useRoute() const route = useRoute()
const authStore = useAuthStore() const authStore = useAuthStore()
@@ -78,11 +79,12 @@ watch(() => workspace, () => {
onMounted(() => { onMounted(() => {
if (process.client) { if (process.client) {
// window.onbeforeunload = () => { window.onbeforeunload = () => {
if (isDirty()) { if (isDirty()) {
return false return false
} }
} }
}
if (!formStore.allLoaded) { if (!formStore.allLoaded) {
formStore.loadAll(workspace.value.id) formStore.loadAll(workspace.value.id)