feat: block navigation on public form page when form is dirty #4813
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?
Another solution could be to simply save responses localstorage and do away with prompts which might not be the best UX.