Skip to content

Conversation

@benjaminleonard
Copy link
Contributor

Fixes #996

Uses useBlocker to prevent user from leaving dirty form. As discussed this isn't foolproof but I think good enough to catch most accidental exits from the fullPageForm.

Related to #1522. The rationale for two approaches on handling unsubmitted forms and persistent form state discussed here: #1522 (comment)

That said, the difference between the two is a little fuzzy, we could also nix the idea of useBlocker completely and use persistent state for the fullPageForm also. I'm open to either solution for this form. What do you think @david-crespo @zephraph ?

CleanShot 2023-05-23 at 16 08 58

if (blocker.state === 'blocked' && !isDirty) {
blocker.reset()
}
}, [blocker, isDirty])
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was surprised this is necessary but I see it's from their example.

Copy link
Contributor

@just-be-dev just-be-dev left a comment

Choose a reason for hiding this comment

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

This is small enough and feels like a net improvement so I'm fine w/ starting here. I think we have to be really careful with populating fields on large forms because the user may populate something lower down in the form, leave, come back and create a new resource that does something unanticipated because they missed the population. I know that's an edge case but for the moment this feels better.

// SideModalForm from inside another form, in which case submitting
// the inner form submits the outer form unless we stop propagation
e.stopPropagation()
form.reset({} as TFieldValues, { keepValues: true })

This comment was marked as resolved.

Copy link
Collaborator

@david-crespo david-crespo left a comment

Choose a reason for hiding this comment

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

Looks good. We should see how it feels and reevaluate in a week or two, maybe we want to use it everywhere. Might be good to note somewhere in the codebase what the limitations are — from my testing it doesn't block refreshes and it doesn't block closing the tab.

Visually I think this is a little flat and wide, like a McDonald's hamburger — could be narrower, maybe center the text?

image

@benjaminleonard
Copy link
Contributor Author

That's the most american comparison this week.

@benjaminleonard benjaminleonard enabled auto-merge (squash) May 23, 2023 19:46
@benjaminleonard benjaminleonard merged commit 7cf95dc into main May 23, 2023
@benjaminleonard benjaminleonard deleted the leave-form-blocker branch May 23, 2023 19:52
@just-be-dev
Copy link
Contributor

🍔

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 user from leaving page with incomplete form

4 participants