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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 13 deletions

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 {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,11 +79,12 @@ watch(() => workspace, () => {
onMounted(() => {
if (process.client) {
// window.onbeforeunload = () => {
window.onbeforeunload = () => {
if (isDirty()) {
return false
}
}
}
if (!formStore.allLoaded) {
formStore.loadAll(workspace.value.id)