Skip to content

Commit

Permalink
Fix: only show confirmation dialog for active forms
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hartmann <[email protected]>
  • Loading branch information
Chartman123 committed Jan 20, 2025
1 parent 8ed1b83 commit 0e84add
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/views/Submit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -608,10 +608,30 @@ export default {
},

/**
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 not archived.
* - The form is not closed.
* - The form is not expired.
* - 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.form.isArchived &&
!this.form.isClosed &&
!this.form.isExpired &&
!this.submitForm &&
Object.keys(this.answers).length !== 0
) {
this.showConfirmLeaveDialog = true
return new Promise((resolve) => {
this.confirmButtonCallback = (val) => {
Expand Down

0 comments on commit 0e84add

Please sign in to comment.