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

Binder: Improve change detection #19260

Closed
onuridrisoglu opened this issue Apr 25, 2024 · 0 comments · Fixed by #19488
Closed

Binder: Improve change detection #19260

onuridrisoglu opened this issue Apr 25, 2024 · 0 comments · Fixed by #19488

Comments

@onuridrisoglu
Copy link
Contributor

Describe your motivation

Currently, when the value of a bound field changes, the binding is considered as "changed" and is included in the changedBindings, regardless of whether the user reverts to the initial value. For example, if the value of a name field is changed from "foo" to "foo bar" and then reverted to "foo", the binding still appears in changedBindings, causing binder.hasChanges() to return true.

It's a common use case to enable the save button only if there is any changes in the form. This way it would be possible to enable the save button only if there are "real" changes.

Describe the solution you'd like

A potential solution is to store the initial value of each binding when the readBean method is invoked. Subsequently, after each value change, this initial value can be compared to the new value. If the new value matches the initial one, the binding would not be marked as "changed," thereby ensuring that changedBindings only includes entries where the current value differs from the initial value.

Describe alternatives you've considered

An alternative solution could involve extending this mechanism to maintain a list of all changes, which would facilitate an "undo" feature. By tracking each change as an entry in a history list, users can easily revert the most recent modifications or even all changes back to the original state.

@tepi tepi added the binder label Apr 26, 2024
@mshabarov mshabarov moved this to 🪵Product backlog in Vaadin Flow ongoing work (Vaadin 10+) Apr 30, 2024
mshabarov added a commit that referenced this issue Aug 23, 2024
Fixes #19260

* Introduced binder change detection for readBean case

* Added equality predicate to Binding level

and deprecated the old handleFieldValueChange method

* Fixed unit test error

* Added default implementation for the new withEqualityPredicate method

* Added missing line from the deprecated method

* Changes for review comments:

- removed bindingInitialValuesMap from Binder, and kept the initial
value in binding level instead
- removed the default implementation for equalityPredicate and now this
feature will only be active if an equalityPredicate is set

* fixed format issues

* Add global setting and default comparison

* Add tests

---------

Co-authored-by: Teppo Kurki <[email protected]>
Co-authored-by: Mikhail Shabarov <[email protected]>
@github-project-automation github-project-automation bot moved this from 🪵Product backlog to Done in Vaadin Flow ongoing work (Vaadin 10+) Aug 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

2 participants