diff options
author | Artur <artur@vaadin.com> | 2017-05-19 14:48:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-19 14:48:42 +0300 |
commit | 91e34500d7112f431c8d576c5992f63cbd1b4cd0 (patch) | |
tree | 4ec38d35681df335ccdfcbe3fedb44e0d59376ce | |
parent | f9eae69b148dc1bad9f63abdc4fc36787c90db04 (diff) | |
download | vaadin-framework-91e34500d7112f431c8d576c5992f63cbd1b4cd0.tar.gz vaadin-framework-91e34500d7112f431c8d576c5992f63cbd1b4cd0.zip |
Clear errors when clearing binder fields (#9364)
Calling readBean(null) should reset the form state to the initial state
it was in before calling writeBean(bean)
-rw-r--r-- | server/src/main/java/com/vaadin/data/Binder.java | 5 | ||||
-rw-r--r-- | server/src/test/java/com/vaadin/data/BinderTest.java | 20 |
2 files changed, 24 insertions, 1 deletions
diff --git a/server/src/main/java/com/vaadin/data/Binder.java b/server/src/main/java/com/vaadin/data/Binder.java index 676030ec22..1c6c4a4591 100644 --- a/server/src/main/java/com/vaadin/data/Binder.java +++ b/server/src/main/java/com/vaadin/data/Binder.java @@ -1561,7 +1561,10 @@ public class Binder<BEAN> implements Serializable { * Clear all the bound fields for this binder. */ private void clearFields() { - bindings.forEach(binding -> binding.getField().clear()); + bindings.forEach(binding -> { + binding.getField().clear(); + clearError(binding.getField()); + }); if (hasChanges()) { fireStatusChangeEvent(false); } diff --git a/server/src/test/java/com/vaadin/data/BinderTest.java b/server/src/test/java/com/vaadin/data/BinderTest.java index 89392be3e3..a521449c04 100644 --- a/server/src/test/java/com/vaadin/data/BinderTest.java +++ b/server/src/test/java/com/vaadin/data/BinderTest.java @@ -442,6 +442,26 @@ public class BinderTest extends BinderTestBase<Binder<Person>, Person> { } @Test + public void readNullBeanRemovesError() { + TextField textField = new TextField(); + binder.forField(textField).asRequired("foobar") + .bind(Person::getFirstName, Person::setFirstName); + Assert.assertTrue(textField.isRequiredIndicatorVisible()); + Assert.assertNull(textField.getErrorMessage()); + + binder.readBean(item); + Assert.assertNull(textField.getErrorMessage()); + + textField.setValue(textField.getEmptyValue()); + Assert.assertTrue(textField.isRequiredIndicatorVisible()); + Assert.assertNotNull(textField.getErrorMessage()); + + binder.readBean(null); + assertTrue(textField.isRequiredIndicatorVisible()); + Assert.assertNull(textField.getErrorMessage()); + } + + @Test public void setRequired_withErrorMessageProvider_fieldGetsRequiredIndicatorAndValidator() { TextField textField = new TextField(); textField.setLocale(Locale.CANADA); |