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 dirty check #157

Merged
merged 14 commits into from
Oct 5, 2021
Merged

Add dirty check #157

merged 14 commits into from
Oct 5, 2021

Conversation

RickLucassen
Copy link
Contributor

This PR adds functionality for dirty checks on accessors.

For each accessor the initial value (this also includes any value through addModeDefaults) is saved and compared to see if this has been changed ever since.

After a succesful save of the FormAccessor the initial value is updated and thus the dirty state is reset.

Each accessor has a isDirty property to check for this state, also a resetDirtyState is present on each accessor to reset this manually.

return false;
}
if (Array.isArray(this.value)) {
return toJS(this.value).length !== this._originalValue.length;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a proper dirty check? Because it looks like it only checks if the array is equal in length. So if I change one value in the array but keep it the same length, will it correctly flag as dirty?

Copy link
Contributor Author

@RickLucassen RickLucassen Oct 5, 2021

Choose a reason for hiding this comment

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

Good catch! I came across this issue while implementing the restore functionality.
This has been fixed in that PR by comparing the values in its stringified form when the lengths are the same.

See: https://github.com/isprojects/mstform/pull/158/files#diff-04b90f51cc34e5843489f6f9e7d93eda3a01491f30b3d902a4bfdff8a1a61ff1R299

@RickLucassen RickLucassen merged commit 2645efb into master Oct 5, 2021
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.

None yet

4 participants