use of com.vaadin.flow.component.HasValidation in project flow by vaadin.
the class ValidationTestView method initView.
private void initView() {
HasValidation field = getValidationComponent();
((Component) field).setId("field");
add(((Component) field));
NativeButton button = new NativeButton("Make the input invalid");
button.setId("invalidate");
button.addClickListener(event -> {
field.setErrorMessage("Invalidated from server");
field.setInvalid(true);
});
add(button);
button = new NativeButton("Make the input valid");
button.setId("validate");
button.addClickListener(event -> {
field.setErrorMessage(null);
field.setInvalid(false);
});
add(button);
}
use of com.vaadin.flow.component.HasValidation in project flow by vaadin.
the class Binder method handleError.
/**
* Handles a validation error emitted when trying to write the value of the
* given field.
*
* @param field
* the field with the invalid value
* @param result
* 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());
}
}
use of com.vaadin.flow.component.HasValidation in project flow by vaadin.
the class Binder method clearError.
/**
* Clears the error condition of the given field, if any.
*
* @param field
* the field with an invalid value
*/
protected void clearError(HasValue<?, ?> field) {
if (field instanceof HasValidation) {
HasValidation fieldWithValidation = (HasValidation) field;
fieldWithValidation.setInvalid(false);
}
}
Aggregations