[Form] Add dirty and clean states, and ability to cancel submit #661
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.
First, a great kudo to @simontaite for inspiring me this. I'm using his plugin on a lot of projects and it works well with FUI.
This PR add the ability to define a state for the form:
clean
ordirty
. Default state isclean
and is changed todirty
when the user change at least one field. Reseting a form also change state toclean
. Theses events are now triggered:onDirty()
onClean()
Dirty fields can be showed by using the
get dirty fields
behavior.State can also be changed programmaticaly by using behaviors
set as clean
andset as dirty
. Its now also possible to prevent a user form leaving the page if the form is indirty
state, usingpreventLeaving: true
, which can be useful when you don't want to loose data.Bonus point: Dropdown are now correctly restored when calling the behavior
reset
.