Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,15 @@ export default {
return this.form.state === FormState.FormClosed
},

/**
* Checks if the current state is active.
*
* @return {boolean} - Returns true if active, otherwise false.
*/
isActive() {
return !this.isArchived && !this.isClosed && !this.isExpired
},

infoMessage() {
let message = ''
if (this.form.isAnonymous) {
Expand Down Expand Up @@ -600,18 +609,38 @@ export default {
* Methods for catching unwanted unload events
*/
beforeWindowUnload(e) {
if (!(this.submitForm || Object.keys(this.answers).length === 0)) {
if (
this.isActive &&
!this.submitForm &&
Object.keys(this.answers).length !== 0
) {
// Cancel the window unload event
e.preventDefault()
e.returnValue = ''
}
},

/**
Check if the form contains unsaved changes, returns true if the the form can be leaved safely, false if the navigation should be canceled.
* Checks if the user is attempting to leave the form under certain conditions
* and shows a confirmation dialog if necessary.
*
* Conditions to show the confirmation dialog:
* - The form is active.
* - The form is not currently submitted.
* - There are answers provided in the form.
*
* If the conditions are met, a confirmation dialog is shown and a promise is returned.
* The promise resolves with the value passed to the confirm button callback.
*
* @return {Promise<boolean>|boolean} - Returns a promise that resolves with the value
* passed to the confirm button callback if the dialog is shown, otherwise returns true.
*/
confirmLeaveForm() {
if (!this.submitForm && Object.keys(this.answers).length !== 0) {
if (
this.isActive &&
!this.submitForm &&
Object.keys(this.answers).length !== 0
) {
this.showConfirmLeaveDialog = true
return new Promise((resolve) => {
this.confirmButtonCallback = (val) => {
Expand Down
Loading