Class ShortField

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<ShortField,Short>
com.vaadin.flow.component.AbstractSinglePropertyField<ShortField,Short>
com.vaadin.flow.component.textfield.TextFieldBase<ShortField,Short>
com.vaadin.flow.component.textfield.AbstractNumberField<ShortField,Short>
org.vaadin.firitin.fields.ShortField
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<ShortField>, com.vaadin.flow.component.CompositionNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<ShortField>, com.vaadin.flow.component.FocusNotifier<ShortField>, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasPlaceholder, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ShortField,Short>,Short>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ShortField,Short>,Short>, com.vaadin.flow.component.InputNotifier, com.vaadin.flow.component.KeyNotifier, com.vaadin.flow.component.shared.HasClearButton, com.vaadin.flow.component.shared.HasClientValidation, com.vaadin.flow.component.shared.HasPrefix, com.vaadin.flow.component.shared.HasSuffix, com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.textfield.TextFieldVariant>, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.component.shared.HasValidationProperties, com.vaadin.flow.component.shared.InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ShortField,Short>,Short>, com.vaadin.flow.component.textfield.HasAutocapitalize, com.vaadin.flow.component.textfield.HasAutocomplete, com.vaadin.flow.component.textfield.HasAutocorrect, com.vaadin.flow.component.textfield.HasPrefixAndSuffix, com.vaadin.flow.data.binder.HasValidator<Short>, com.vaadin.flow.data.value.HasValueChangeMode, Serializable

@Tag("vaadin-integer-field") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.5.2") @NpmPackage(value="@vaadin/integer-field",version="24.5.2") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/integer-field/src/vaadin-integer-field.js") public class ShortField extends com.vaadin.flow.component.textfield.AbstractNumberField<ShortField,Short> implements com.vaadin.flow.component.shared.HasThemeVariant<com.vaadin.flow.component.textfield.TextFieldVariant>
ShortField is an extension of Text Field that only accepts Short numbers. This class is pretty much 1-1 copy-paste from the IntegerField in the Vaadin 24.5, but editing Short instead of Integer.

Validation

ShortField comes with a built-in validation mechanism based on constraints. Validation is triggered whenever the user applies an input change, for example by pressing Enter or blurring the field. Programmatic value changes trigger validation as well. In eager and lazy value change modes, validation is also triggered on every character press with a delay according to the selected mode.

Validation verifies that the value is parsable into Short and satisfies the specified constraints. If validation fails, the component is marked as invalid and an error message is displayed below the input.

The following constraints are supported:

Error messages for unparsable input and constraints can be configured with the ShortField.ShortFieldI18n object, using the respective properties. If you want to provide a single catch-all error message, you can also use the setErrorMessage(String) method. Note that such an error message will take priority over i18n error messages if both are set.

For more advanced validation that requires custom rules, you can use Binder. By default, before running custom validators, Binder will also check if the value is parsable and satisfies the component constraints, displaying error messages from the ShortField.ShortFieldI18n object. The exception is the required constraint, for which Binder provides its own API, see asRequired().

However, if Binder doesn't fit your needs and you want to implement fully custom validation logic, you can disable the constraint validation by setting AbstractNumberField.setManualValidation(boolean) to true. This will allow you to control the invalid state and the error message manually using HasValidationProperties.setInvalid(boolean) and setErrorMessage(String) API.

Author:
Vaadin Ltd.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    The internationalization properties for ShortField.

    Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField

    com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier

    com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier

    com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.shared.HasClientValidation

    com.vaadin.flow.component.shared.HasClientValidation.ClientValidatedEvent

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue

    com.vaadin.flow.component.HasValue.ValueChangeEvent<V>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>
  • Field Summary

    Fields inherited from interface com.vaadin.flow.component.textfield.HasAutocapitalize

    AUTOCAPITALIZE_ATTRIBUTE

    Fields inherited from interface com.vaadin.flow.component.textfield.HasAutocomplete

    AUTOCOMPLETE_ATTRIBUTE

    Fields inherited from interface com.vaadin.flow.component.textfield.HasAutocorrect

    AUTOCORRECT_ATTRIBUTE

    Fields inherited from interface com.vaadin.flow.data.value.HasValueChangeMode

    DEFAULT_CHANGE_TIMEOUT
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs an empty ShortField.
    ShortField(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ShortField,Short>> listener)
    Constructs an empty ShortField with a value change listener.
    Constructs an empty ShortField with the given label.
    ShortField(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ShortField,Short>> listener)
    Constructs an empty ShortField with a value change listener and a label.
    ShortField(String label, Short initialValue, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ShortField,Short>> listener)
    Constructs a ShortField with a value change listener, a label and an initial value.
    ShortField(String label, String placeholder)
    Constructs an empty ShortField with the given label and placeholder text.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the internationalization object previously set for this component.
    int
    Gets the maximum value for the field.
    int
    Gets the minimum value for this field.
    int
    Gets the allowed number intervals for this field.
    void
    setErrorMessage(String errorMessage)
    void
    Sets the internationalization object for this component.
    void
    setMax(int max)
    Sets the maximum value for the field.
    void
    setMin(int min)
    Sets the minimum value for the field.
    void
    setRequiredIndicatorVisible(boolean required)
     
    void
    setStep(int step)
    Sets the allowed number intervals for this field.

    Methods inherited from class com.vaadin.flow.component.textfield.AbstractNumberField

    addValidationStatusChangeListener, getDefaultValidator, getEmptyValue, getMaxDouble, getMinDouble, getStepDouble, getValue, isStepButtonsVisible, onAttach, setI18n, setManualValidation, setMax, setMin, setModelValue, setStep, setStepButtonsVisible, setValue, setValueChangeMode, validate

    Methods inherited from class com.vaadin.flow.component.textfield.TextFieldBase

    addToInput, addToPrefix, addToSuffix, getAriaLabel, getAriaLabelledBy, getTitle, getValueChangeMode, getValueChangeTimeout, isAutofocus, isAutoselect, isRequired, isRequiredIndicatorVisible, setAriaLabel, setAriaLabelledBy, setAutofocus, setAutoselect, setLabel, setRequired, setTitle, setValueChangeTimeout

    Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField

    getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEvent

    Methods inherited from class com.vaadin.flow.component.AbstractField

    addValueChangeListener, isEmpty, valueEquals

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

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

    addAttachListener

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

    addBlurListener

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

    addCompositionEndListener, addCompositionStartListener, addCompositionUpdateListener

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

    addDetachListener

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

    addFocusShortcut, blur, focus, getTabIndex, setTabIndex

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

    addFocusListener

    Methods inherited from interface com.vaadin.flow.component.textfield.HasAutocapitalize

    getAutocapitalize, setAutocapitalize

    Methods inherited from interface com.vaadin.flow.component.textfield.HasAutocomplete

    getAutocomplete, setAutocomplete

    Methods inherited from interface com.vaadin.flow.component.textfield.HasAutocorrect

    isAutocorrect, setAutocorrect

    Methods inherited from interface com.vaadin.flow.component.shared.HasClearButton

    isClearButtonVisible, setClearButtonVisible

    Methods inherited from interface com.vaadin.flow.component.shared.HasClientValidation

    addClientValidatedEventListener

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

    getElement

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

    isEnabled, setEnabled

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

    getHelperComponent, getHelperText, setHelperComponent, setHelperText

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

    getLabel

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

    getPlaceholder, setPlaceholder

    Methods inherited from interface com.vaadin.flow.component.shared.HasPrefix

    getPrefixComponent, setPrefixComponent

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

    getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

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

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface com.vaadin.flow.component.shared.HasSuffix

    getSuffixComponent, setSuffixComponent

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

    addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

    Methods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant

    addThemeVariants, removeThemeVariants

    Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip

    getTooltip, setTooltipText

    Methods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties

    getErrorMessage, isInvalid, setInvalid

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

    addValueChangeListener, clear, getOptionalValue, isEmpty

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

    isReadOnly, setReadOnly

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

    addInputListener

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

    addKeyDownListener, addKeyDownListener, addKeyPressListener, addKeyPressListener, addKeyUpListener, addKeyUpListener
  • Constructor Details

    • ShortField

      public ShortField()
      Constructs an empty ShortField.
    • ShortField

      public ShortField(String label)
      Constructs an empty ShortField with the given label.
      Parameters:
      label - the text to set as the label
    • ShortField

      public ShortField(String label, String placeholder)
      Constructs an empty ShortField with the given label and placeholder text.
      Parameters:
      label - the text to set as the label
      placeholder - the placeholder text to set
    • ShortField

      public ShortField(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ShortField,Short>> listener)
      Constructs an empty ShortField with a value change listener.
      Parameters:
      listener - the value change listener
      See Also:
      • AbstractField.addValueChangeListener(ValueChangeListener)
    • ShortField

      public ShortField(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ShortField,Short>> listener)
      Constructs an empty ShortField with a value change listener and a label.
      Parameters:
      label - the text to set as the label
      listener - the value change listener
      See Also:
      • TextFieldBase.setLabel(String)
      • AbstractField.addValueChangeListener(ValueChangeListener)
    • ShortField

      public ShortField(String label, Short initialValue, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ShortField,Short>> listener)
      Constructs a ShortField with a value change listener, a label and an initial value.
      Parameters:
      label - the text to set as the label
      initialValue - the initial value
      listener - the value change listener
      See Also:
      • TextFieldBase.setLabel(String)
      • AbstractNumberField.setValue(Object)
      • AbstractField.addValueChangeListener(ValueChangeListener)
  • Method Details

    • setErrorMessage

      public void setErrorMessage(String errorMessage)

      Distinct error messages for unparsable input and different constraints can be configured with the ShortField.ShortFieldI18n object, using the respective properties. However, note that the error message set with setErrorMessage(String) will take priority and override any i18n error messages if both are set.

      Specified by:
      setErrorMessage in interface com.vaadin.flow.component.HasValidation
      Specified by:
      setErrorMessage in interface com.vaadin.flow.component.shared.HasValidationProperties
    • setRequiredIndicatorVisible

      public void setRequiredIndicatorVisible(boolean required)
      Specified by:
      setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ShortField,Short>,Short>
      Specified by:
      setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ShortField,Short>,Short>
      Overrides:
      setRequiredIndicatorVisible in class com.vaadin.flow.component.textfield.TextFieldBase<ShortField,Short>
      See Also:
    • setMin

      public void setMin(int min)
      Sets the minimum value for the field. This will configure the field to invalidate if the entered value is below the minimum. It will also limit the decrementing of the value when step buttons are enabled.

      The minimum value is inclusive.

      Parameters:
      min - the minimum short value to set
      See Also:
    • getMin

      public int getMin()
      Gets the minimum value for this field. The constraint activates only if the value was explicitly set with setMin(int).
      Returns:
      the minimum short value
      See Also:
    • setMax

      public void setMax(int max)
      Sets the maximum value for the field. This will configure the field to invalidate if the entered value is above the maximum. It will also limit the incrementing of the value when step buttons are enabled.

      The maximum value is inclusive.

      Parameters:
      max - the maximum short value to set
      See Also:
    • getMax

      public int getMax()
      Gets the maximum value for the field. The constraint activates only if the value was explicitly set with setMax(int).
      Returns:
      the maximum short value
      See Also:
    • setStep

      public void setStep(int step)
      Sets the allowed number intervals for this field. This specifies how much the value will be increased/decreased when clicking on the step buttons. It is also used to invalidate the field, if the value doesn't align with the specified step and min (if explicitly specified by developer).
      Parameters:
      step - the new step to set
      Throws:
      IllegalArgumentException - if the argument is less or equal to zero.
    • getStep

      public int getStep()
      Gets the allowed number intervals for this field. The constraint activates only if the step was explicitly set with setStep(int).
      Returns:
      the step property of the field
      See Also:
    • getI18n

      public ShortField.ShortFieldI18n getI18n()
      Gets the internationalization object previously set for this component.

      NOTE: Updating the instance that is returned from this method will not update the component if not set again using setI18n(ShortFieldI18n)

      Overrides:
      getI18n in class com.vaadin.flow.component.textfield.AbstractNumberField<ShortField,Short>
      Returns:
      the i18n object or null if no i18n object has been set
    • setI18n

      public void setI18n(ShortField.ShortFieldI18n i18n)
      Sets the internationalization object for this component.
      Parameters:
      i18n - the i18n object, not null