Class NumberField

  • All Implemented Interfaces:
    com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<NumberField>, com.vaadin.flow.component.CompositionNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<NumberField>, com.vaadin.flow.component.FocusNotifier<NumberField>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, 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<NumberField,​Double>,​Double>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<NumberField,​Double>,​Double>, com.vaadin.flow.component.InputNotifier, com.vaadin.flow.component.KeyNotifier, HasAllowedCharPattern, HasClearButton, HasThemeVariant<TextFieldVariant>, HasTooltip, HasAutocapitalize, HasAutocomplete, HasAutocorrect, HasPrefixAndSuffix, com.vaadin.flow.data.binder.HasValidator<Double>, com.vaadin.flow.data.value.HasValueChangeMode, Serializable

    public class NumberField
    extends AbstractNumberField<NumberField,​Double>
    Number Field sports many of the same features as Text Field but only accepts numeric input. The input can be decimal, integral or big decimal. You can specify a unit as a prefix or suffix for the field.
    Author:
    Vaadin Ltd.
    See Also:
    Serialized Form
    • Constructor Detail

      • NumberField

        public NumberField()
        Constructs an empty NumberField.
      • NumberField

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

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

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

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

        public NumberField​(String label,
                           Double initialValue,
                           com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<NumberField,​Double>> listener)
        Constructs a NumberField 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:
        AbstractNumberField.setLabel(String), AbstractField.setValue(Object), AbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)
    • Method Detail

      • getMin

        public double getMin()
        The minimum value of the field.
        Returns:
        the min property from the webcomponent
      • getMax

        public double getMax()
        The maximum value of the field.
        Returns:
        the max property from the webcomponent
      • setStep

        public void setStep​(double step)
        Sets the allowed number intervals of the field. This specifies how much the value will be increased/decreased. It is also used to invalidate the field, if the value doesn't align with the specified step and min (if specified by user).
        Overrides:
        setStep in class AbstractNumberField<NumberField,​Double>
        Parameters:
        step - the new step to set
        Throws:
        IllegalArgumentException - if the argument is less or equal to zero.
      • getStep

        public double getStep()
        Specifies the allowed number intervals of the field.
        Returns:
        the step property from the webcomponent
      • setMaxLength

        @Deprecated
        public void setMaxLength​(int maxLength)
        Deprecated.
        Not supported by NumberField (as it's built on <input type="number"> in HTML). You can set numeric value constraints with setMin(double), setMax(double) and setStep(double).
        Maximum number of characters (in Unicode code points) that the user can enter.
        Parameters:
        maxLength - the maximum length
      • getMaxLength

        @Deprecated
        public int getMaxLength()
        Deprecated.
        Not supported by NumberField (as it's built on <input type="number"> in HTML). You can set numeric value constraints with setMin(double), setMax(double) and setStep(double).
        Maximum number of characters (in Unicode code points) that the user can enter.
        Returns:
        the maxlength property from the webcomponent
      • setMinLength

        @Deprecated
        public void setMinLength​(int minLength)
        Deprecated.
        Not supported by NumberField (as it's built on <input type="number"> in HTML). You can set numeric value constraints with setMin(double), setMax(double) and setStep(double).
        Minimum number of characters (in Unicode code points) that the user can enter.
        Parameters:
        minLength - the minimum length
      • getMinLength

        @Deprecated
        public int getMinLength()
        Deprecated.
        Not supported by NumberField (as it's built on <input type="number"> in HTML). You can set numeric value constraints with setMin(double), setMax(double) and setStep(double).
        Minimum number of characters (in Unicode code points) that the user can enter.
        Returns:
        the minlength property from the webcomponent
      • isPreventInvalidInput

        @Deprecated
        public boolean isPreventInvalidInput()
        Deprecated.
        Not supported by NumberField (as it's built on <input type="number"> in HTML). You can set numeric value constraints with setMin(double), setMax(double) and setStep(double). For setting a custom value pattern and preventing invalid input, use the TextField component instead.
        When set to true, user is prevented from typing a value that conflicts with the given pattern.
        Returns:
        the preventInvalidInput property from the webcomponent
      • setPreventInvalidInput

        @Deprecated
        public void setPreventInvalidInput​(boolean preventInvalidInput)
        Deprecated.
        Not supported by NumberField (as it's built on <input type="number"> in HTML). You can set numeric value constraints with setMin(double), setMax(double) and setStep(double). For setting a custom value pattern and preventing invalid input, use the TextField component instead.
        Description copied from class: GeneratedVaadinTextField

        Description copied from corresponding location in WebComponent:

        When set to true, user is prevented from typing a value that conflicts with the given pattern, maxlength or minlength properties.

        Overrides:
        setPreventInvalidInput in class GeneratedVaadinTextField<NumberField,​Double>
        Parameters:
        preventInvalidInput - the boolean value to set
      • setPattern

        @Deprecated
        public void setPattern​(String pattern)
        Deprecated.
        Not supported by NumberField (as it's built on <input type="number"> in HTML). You can set numeric value constraints with setMin(double), setMax(double) and setStep(double). For setting a custom value pattern, use the TextField component instead.
        Description copied from class: GeneratedVaadinTextField

        Description copied from corresponding location in WebComponent:

        A regular expression that the value is checked against. The pattern must match the entire value, not just some subset.

        Overrides:
        setPattern in class GeneratedVaadinTextField<NumberField,​Double>
        Parameters:
        pattern - the String value to set
      • getPattern

        @Deprecated
        public String getPattern()
        Deprecated.
        Not supported by NumberField (as it's built on <input type="number"> in HTML). You can set numeric value constraints with setMin(double), setMax(double) and setStep(double). For setting a custom value pattern, use the TextField component instead.
        A regular expression that the value is checked against. The pattern must match the entire value, not just some subset.
        Returns:
        the pattern property from the webcomponent