Search in sources :

Example 1 with HasValidation

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);
}
Also used : NativeButton(com.vaadin.flow.component.html.NativeButton) Component(com.vaadin.flow.component.Component) HasValidation(com.vaadin.flow.component.HasValidation)

Example 2 with HasValidation

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());
    }
}
Also used : HasValidation(com.vaadin.flow.component.HasValidation)

Example 3 with HasValidation

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);
    }
}
Also used : HasValidation(com.vaadin.flow.component.HasValidation)

Aggregations

HasValidation (com.vaadin.flow.component.HasValidation)3 Component (com.vaadin.flow.component.Component)1 NativeButton (com.vaadin.flow.component.html.NativeButton)1