|
47 | 47 | import com.vaadin.flow.data.binder.testcomponents.TestTextField; |
48 | 48 | import com.vaadin.flow.data.converter.Converter; |
49 | 49 | import com.vaadin.flow.data.converter.StringToBigDecimalConverter; |
| 50 | +import com.vaadin.flow.data.converter.StringToDoubleConverter; |
50 | 51 | import com.vaadin.flow.data.converter.StringToIntegerConverter; |
51 | 52 | import com.vaadin.flow.data.validator.IntegerRangeValidator; |
52 | 53 | import com.vaadin.flow.data.validator.NotEmptyValidator; |
@@ -1742,6 +1743,35 @@ public void invalidUsage_modifyFieldsInsideValidator_binderDoesNotThrow() { |
1742 | 1743 | Assert.assertTrue(validatorIsExecuted.get()); |
1743 | 1744 | } |
1744 | 1745 |
|
| 1746 | + @Test |
| 1747 | + public void validationShouldNotRunTwice() { |
| 1748 | + TestTextField salaryField = new TestTextField(); |
| 1749 | + AtomicInteger count = new AtomicInteger(0); |
| 1750 | + item.setSalaryDouble(100d); |
| 1751 | + binder.forField(salaryField) |
| 1752 | + .withConverter(new StringToDoubleConverter("")) |
| 1753 | + .bind(Person::getSalaryDouble, Person::setSalaryDouble); |
| 1754 | + binder.setBean(item); |
| 1755 | + binder.addValueChangeListener(event -> { |
| 1756 | + count.incrementAndGet(); |
| 1757 | + }); |
| 1758 | + |
| 1759 | + salaryField.setValue("1000"); |
| 1760 | + assertTrue(binder.isValid()); |
| 1761 | + assertEquals(1, count.get()); |
| 1762 | + |
| 1763 | + salaryField.setValue("salary"); |
| 1764 | + assertFalse(binder.isValid()); |
| 1765 | + assertEquals(2, count.get()); |
| 1766 | + |
| 1767 | + salaryField.setValue("2000"); |
| 1768 | + |
| 1769 | + // Without fix for #12356 count will be 5 |
| 1770 | + assertEquals(3, count.get()); |
| 1771 | + |
| 1772 | + assertEquals(new Double(2000), item.getSalaryDouble()); |
| 1773 | + } |
| 1774 | + |
1745 | 1775 | @Test |
1746 | 1776 | public void setValidationErrorHandler_handlerIsSet_handlerMethodsAreCalled() { |
1747 | 1777 | TestTextField testField = new TestTextField(); |
|
0 commit comments