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

Don't remove error message when the field becomes valid #3552

Merged
merged 1 commit into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions flow-data/src/main/java/com/vaadin/flow/data/binder/Binder.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.util.stream.Stream;

import com.googlecode.gentyref.GenericTypeReflector;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.HasText;
import com.vaadin.flow.component.HasValidation;
Expand Down Expand Up @@ -621,7 +620,7 @@ default BindingBuilder<BEAN, TARGET> asRequired(String errorMessage) {
* @see HasValue#setRequiredIndicatorVisible(boolean)
* @see HasValue#isEmpty()
* @return this binding, for chaining
*
*
*/
default BindingBuilder<BEAN, TARGET> asRequired() {
return asRequired(context -> "");
Expand Down Expand Up @@ -2026,7 +2025,7 @@ public Registration addStatusChangeListener(StatusChangeListener listener) {

/**
* Adds a listener to the binder.
*
*
* @param eventType
* the type of the event
* @param method
Expand Down Expand Up @@ -2111,11 +2110,11 @@ protected <FIELDVALUE, TARGET> BindingBuilder<BEAN, TARGET> doCreateBinding(
* the validation error result
*/
protected void handleError(HasValue<?, ?> field, ValidationResult result) {
if (field instanceof HasValidation) {
HasValidation fieldWithValidation = (HasValidation) field;
fieldWithValidation.setInvalid(true);
fieldWithValidation.setErrorMessage(result.getErrorMessage());
}
if (field instanceof HasValidation) {
HasValidation fieldWithValidation = (HasValidation) field;
fieldWithValidation.setInvalid(true);
fieldWithValidation.setErrorMessage(result.getErrorMessage());
}
}

/**
Expand All @@ -2128,7 +2127,6 @@ protected void clearError(HasValue<?, ?> field) {
if (field instanceof HasValidation) {
HasValidation fieldWithValidation = (HasValidation) field;
fieldWithValidation.setInvalid(false);
fieldWithValidation.setErrorMessage(null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.vaadin.flow.data.binder;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.isEmptyString;
Expand Down Expand Up @@ -476,7 +475,7 @@ public void setRequired_withErrorMessage_fieldGetsRequiredIndicatorAndValidator(
Assert.assertEquals("foobar", componentErrors.get(textField));

textField.setValue("value");
assertThat(textField.getErrorMessage(), isEmptyString());
assertFalse(textField.isInvalid());
assertTrue(textField.isRequiredIndicatorVisible());
}

Expand Down Expand Up @@ -526,7 +525,7 @@ public void setRequired_withErrorMessageProvider_fieldGetsRequiredIndicatorAndVa
Assert.assertEquals(1, invokes.get());

textField.setValue("value");
assertThat(textField.getErrorMessage(), isEmptyString());
assertFalse(textField.isInvalid());
assertTrue(textField.isRequiredIndicatorVisible());
}

Expand Down Expand Up @@ -880,8 +879,7 @@ public void execute_binding_status_handler_from_binder_status_handler() {

// Restore values and test no errors.
ageField.setValue(String.valueOf(initialAge));
assertThat("There should be no error", ageField.getErrorMessage(),
is(""));
assertFalse("The field should be valid", ageField.isInvalid());

bindingHandler.expectingError = false;
nameField.setValue(initialName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package com.vaadin.flow.data.binder;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.isEmptyOrNullString;

import java.io.ByteArrayOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
Expand Down Expand Up @@ -78,8 +75,6 @@ void assertInvalidField(String expectedErrorMessage, HasValidation field) {
}

void assertValidField(HasValidation field) {
assertThat("The field should contain no error message",
field.getErrorMessage(), isEmptyOrNullString());
Assert.assertFalse("The field should be valid", field.isInvalid());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ public interface HasValidation {

/**
* Sets an error message to the component.
* <p>
* The Web Component is responsible for deciding when to show the error
* message to the user, and this is usually triggered by triggering the
* invalid state for the Web Component. Which means that there is no need to
* clean up the message when component becomes valid (otherwise it may lead
* to undesired visual effects).
*
* @param errorMessage
* a new error message
Expand All @@ -40,6 +46,10 @@ public interface HasValidation {

/**
* Sets the validity of the component input.
* <p>
* When component becomes valid it hides the error message by itself, so
* there is no need to clean up the error message via the
* {@link #setErrorMessage(String)} call.
*
* @param invalid
* new value for component input validity
Expand Down