You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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]>
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 inchangedBindings
, causingbinder.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.
The text was updated successfully, but these errors were encountered: