Skip to content

Add update to reset value along with _pristineValue#432

Open
jganz wants to merge 10 commits into
christianalfoni:masterfrom
jganz:master
Open

Add update to reset value along with _pristineValue#432
jganz wants to merge 10 commits into
christianalfoni:masterfrom
jganz:master

Conversation

@jganz
Copy link
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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