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

Add update to reset value along with _pristineValue #432

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

jganz
Copy link

@jganz jganz commented Mar 24, 2017

I'm wanting the ability to update the form inputs to a set of values and update the pristine value along with this too.

@aesopwolf
Copy link
Collaborator

This looks fine, but I'm hesitant to expose new methods. What's the use case here? Any reason resetValue doesn't suffice?

@jganz
Copy link
Author

jganz commented Apr 13, 2017

On many of my pages I'm including multiple forms on a component and have an 'Apply' button on the parent component for submitting changes. The user can make additional changes to the form inputs and click apply multiple times. I am calling my updateModel method after my the changes have been applied. There is also a 'Cancel' button on my page to allow the user to revert changes since the last apply, which I handle by calling resetForm.

I was having issues before in cases where a user would apply changes, then set the field back to the original values and try to click apply, because I have logic trying to determine if the form has changed from its pristine state, because the _pristineValue and the new current value were the same.

We also try to keep track of any unsaved changes on the page and bring up a dialog if the user tries to navigate away before hitting 'Apply'. The same logic for determining if the form is Changed compares the currentValues against the _pristineValue. So, if a user edits a form, then edits it back to its pristine value, I want them to be able to navigate away without getting the dialog.

Additionally, there were issues where if the user made changes, then clicked apply any number of times, and then wanted to cancel changes, I didn't want to have to keep a state of the most recent applied settings to resetForm to.

mpelham pushed a commit to smashgg/formsy-react that referenced this pull request Aug 1, 2017
@mpelham
Copy link

mpelham commented Aug 2, 2017

We definitely have similar use cases that this PR solves.

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.

3 participants