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

feat: block navigation on public form page when form is dirty #4813

Closed
wants to merge 3 commits into from

Conversation

darrelhong
Copy link
Contributor

@darrelhong darrelhong commented Sep 7, 2022

Closes #4793

the existing useNavigationPrompt can be used to fulfill the goal of preventing accidental navigation after form is modified.

Currently the implementation simply uses the isDirty variable provided useForm.formState to determine if navigation should be blocked. When a text field is touched and unfocused with no input change, it is considered dirty already, so if that is not the desired behaviour, further logic is needed perhaps similar to holdingStateDate in the form builder. One very important consideration here is I'm not sure if there is a situation when the isDirty=true but navigation is actually allowed.

Other than the submit button and switch to react, the public form page should not have any links that redirects the page using react-router (might be wrong here, need more context), so the only way of exiting the page is using browser functions. Thus instead of using the underlying react-router-dom functions, native web apis can be used instead for simplicity. The functionality remains the same in my testing.

The user flow for switch to react is also affected as the prompt will be shown after the feedback modal. Not sure if this is desirable and whats the best way to go about this, perhaps there is an easy way to transfer data when switching to angular?

Screen Shot 2022-09-07 at 2 11 10 PM

Another solution could be to simply save responses localstorage and do away with prompts which might not be the best UX.

@darrelhong
Copy link
Contributor Author

@wanlingt will close this PR if its not needed anymore

@wanlingt
Copy link
Contributor

@wanlingt will close this PR if its not needed anymore

Hi @darrelhong , thanks for your work on this and apologies for taking a while to get to your PR. Displaying the prompt when clicking switch back to angular might cause some confusion to users, additionally there are other links in the form footer that navigate away from the page. We could limit this to the back and forward button events for now, let me know what you think!

@darrelhong darrelhong changed the base branch from form-v2/develop to develop January 28, 2023 08:13
@darrelhong
Copy link
Contributor Author

@wanlingt luckily it looks like all the footer links open in a new tab, so navigation is not affected. For the case of switching to angular, I have updated to not block navigation.

@darrelhong darrelhong changed the title WIP: block navigation on public form page when form is dirty feat: block navigation on public form page when form is dirty Mar 13, 2023
@darrelhong
Copy link
Contributor Author

@wanlingt any update on this? would like to get it merged if possible

@foochifa
Copy link
Contributor

Heya @darrelhong we will be removing angular and the feedback modal #6190! Thanks for your contribution, but will be closing this!

@foochifa foochifa closed this May 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prevent accidental navigation on public form page
3 participants