Interface HasValidationProperties

All Superinterfaces:
HasElement, HasValidation, Serializable
All Known Implementing Classes:
AbstractNumberField, BigDecimalField, Checkbox, CheckboxGroup, ComboBox, ComboBoxBase, CustomField, DatePicker, DateTimePicker, EmailField, IntegerField, MultiSelectComboBox, NumberField, PasswordField, RadioButtonGroup, RangeSlider, Select, Slider, TextArea, TextField, TextFieldBase, TimePicker

public interface HasValidationProperties extends HasElement, HasValidation
Mixin interface for components that provide properties for setting invalid state and error message string to show when invalid.
Author:
Vaadin Ltd
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Binds the component's error message to the provided signal so that the error message is kept in sync with the signal's current value.
    default void
    Binds a given boolean signal to the invalid state of the component.
    default String
    Gets the error message displayed for all constraint violations if it has been set with setErrorMessage(String).
    default boolean
    Gets whether the component is currently in invalid state.
    default void
    setErrorMessage(String errorMessage)
    Sets a single error message to display for all constraint violations.
    default void
    setInvalid(boolean invalid)
    Sets the invalid state of the component.

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface com.vaadin.flow.component.HasValidation

    setManualValidation
  • Method Details

    • setErrorMessage

      default void setErrorMessage(String errorMessage)
      Sets a single error message to display for all constraint violations. The error message will only appear when the component is flagged as invalid, either as a result of constraint validation or by the developer through setInvalid(boolean) if manual validation mode is enabled.
      Specified by:
      setErrorMessage in interface HasValidation
      Parameters:
      errorMessage - the error message to set, or null to clear
    • getErrorMessage

      default String getErrorMessage()
      Gets the error message displayed for all constraint violations if it has been set with setErrorMessage(String). Otherwise, gets the current i18n error message if the value is currently invalid.
      Specified by:
      getErrorMessage in interface HasValidation
      Returns:
      the error message
    • bindErrorMessage

      default void bindErrorMessage(Signal<String> signal)
      Binds the component's error message to the provided signal so that the error message is kept in sync with the signal's current value.

      Passing null as the signal removes any existing binding. When unbinding, the current error message is left unchanged.

      While a binding is active, manual calls to HasValidation.setErrorMessage(String) throw a com.vaadin.flow.signals.BindingActiveException. Bindings are lifecycle-aware and only active while the owning Component is in attached state; they are deactivated while the component is in detached state.

      Binds a given signal to the single error message to display for all constraint violations. The error message will only appear when the component is flagged as invalid, either as a result of constraint validation or by the developer through setInvalid(boolean) if manual validation mode is enabled.

      Signal's value null clears the error message.

      Specified by:
      bindErrorMessage in interface HasValidation
      Parameters:
      signal - the signal to bind the error message to, not null
      Since:
      25.1
    • setInvalid

      default void setInvalid(boolean invalid)
      Sets the invalid state of the component.

      NOTE: If you need to manually control the invalid state, enable manual validation mode with HasValidation.setManualValidation(boolean) to avoid potential conflicts between your custom validation and the component's constraint validation.

      Specified by:
      setInvalid in interface HasValidation
      Parameters:
      invalid - true for invalid, false for valid
    • isInvalid

      default boolean isInvalid()
      Gets whether the component is currently in invalid state.
      Specified by:
      isInvalid in interface HasValidation
      Returns:
      true for invalid, false for valid
    • bindInvalid

      default void bindInvalid(Signal<Boolean> signal)
      Binds a given boolean signal to the invalid state of the component.

      The invalid state controls whether the component is considered invalid and whether a possible error message is shown. If manual validation mode is enabled with HasValidation.setManualValidation(boolean), then the value provided by the bound signal determines the visual invalid state of the component.

      Signal's value null is treated as false.

      Specified by:
      bindInvalid in interface HasValidation
      Parameters:
      signal - the signal to bind the invalid state to, not null
      Since:
      25.1