Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement warning when leaving an unsubmitted form #1310

Merged
merged 1 commit into from
Oct 16, 2023

Conversation

Chartman123
Copy link
Collaborator

Fixes #319 by adding a warning

Signed-off-by: Christian Hartmann chris-hartmann@gmx.de

@Chartman123 Chartman123 added the 2. developing Work in progress label Aug 23, 2022
@Chartman123 Chartman123 added this to the 3.0 milestone Aug 23, 2022
@Chartman123 Chartman123 self-assigned this Aug 23, 2022
@Chartman123
Copy link
Collaborator Author

@jotoeri any ideas why the custom message isn't shown in the window.confirm() dialog?

@jotoeri
Copy link
Member

jotoeri commented Aug 26, 2022

Seems like just confirm should work. But to be honest, i currently can't tell you exactly, why. 😆

if (!confirm(t('forms', 'Are you sure you want to delete {title}?', { title: this.formTitle }))) {

@Chartman123
Copy link
Collaborator Author

@jotoeri Tried it with just confirm() but doesn't work either... Even with static text. Did just research and it seems that it doesn't accept custom text for the onbeforeunload event

@Chartman123 Chartman123 added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Aug 26, 2022
@Chartman123 Chartman123 marked this pull request as ready for review August 26, 2022 21:18
@Chartman123 Chartman123 force-pushed the enh/warn_before_leave branch 2 times, most recently from a65702b to 09cb5a2 Compare August 31, 2022 18:12
@Chartman123 Chartman123 force-pushed the enh/warn_before_leave branch 3 times, most recently from e67b140 to 2eac9cf Compare September 6, 2022 20:41
@jotoeri
Copy link
Member

jotoeri commented Sep 14, 2022

Ok, sorry @Chartman123 i checked it once before quickly, but i definitely have not time to get into detail currently. Needs probably to be postponed.

@Chartman123
Copy link
Collaborator Author

No problem, I think the design parts are more important for 3.0 than this here :)

@susnux
Copy link
Collaborator

susnux commented Dec 28, 2022

confirm and alert are not allowed within beforeunload.
Also all browser dropped support for custom messages, so you only can use the default one.

Chrome removed support for custom message in ver 51
Opera removed support for custom message in ver 38
Firefox removed support for custom message in ver 44.0
Safari removed support for custom message in ver 9.1

Copy link
Collaborator

@susnux susnux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently every time you open the submit view a confirmation dialog is shown, see code comment.

Moreover if you click to stay on the site, an error is thrown in the console because the navigation gets canceled (as requested) by the navigation guard.
So we should add a catch block to the router.push calls on the TopBar component and ignore every navigation guard related errors.

src/views/Submit.vue Outdated Show resolved Hide resolved
@Chartman123
Copy link
Collaborator Author

@susnux Thanks for your input :) I'm also planning to move the warning to a modal. If you want, you can help me there. Everytime I tried it ended up being even worse 😆

@Chartman123 Chartman123 force-pushed the enh/warn_before_leave branch 2 times, most recently from 8cb813f to a23c6dd Compare September 30, 2023 21:35
@Chartman123
Copy link
Collaborator Author

Chartman123 commented Sep 30, 2023

@susnux I think I got this working as expected right now. I think we should merge this without the modal, so that we can take it as a basis for @hamza221's PR regarding the local storage.

@Chartman123 Chartman123 force-pushed the enh/warn_before_leave branch 2 times, most recently from 4162781 to 7f7f2ad Compare September 30, 2023 21:55
@Chartman123 Chartman123 added enhancement New feature or request javascript Javascript related ticket 3. to review Waiting for reviews feature: 📝 submitting responses and removed 2. developing Work in progress labels Oct 2, 2023
@Chartman123 Chartman123 force-pushed the enh/warn_before_leave branch 2 times, most recently from 19613b9 to c3cddcd Compare October 6, 2023 17:46
src/views/Submit.vue Outdated Show resolved Hide resolved
src/views/Submit.vue Outdated Show resolved Hide resolved
src/views/Submit.vue Outdated Show resolved Hide resolved
src/views/Submit.vue Outdated Show resolved Hide resolved
src/views/Submit.vue Outdated Show resolved Hide resolved
src/views/Submit.vue Show resolved Hide resolved
src/views/Submit.vue Outdated Show resolved Hide resolved
Signed-off-by: Christian Hartmann <chris-hartmann@gmx.de>
Copy link
Collaborator

@susnux susnux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works now perfectly!

@susnux susnux merged commit 30cda62 into main Oct 16, 2023
22 checks passed
@susnux susnux deleted the enh/warn_before_leave branch October 16, 2023 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews enhancement New feature or request feature: 📝 submitting responses javascript Javascript related ticket
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alert when leaving the page with an unfinished filled form
3 participants