Class NumberField

All Implemented Interfaces:
AttachNotifier, BlurNotifier<NumberField>, CompositionNotifier, DetachNotifier, Focusable<NumberField>, FocusNotifier<NumberField>, HasAriaLabel, HasElement, HasEnabled, HasHelper, HasLabel, HasPlaceholder, HasSize, HasStyle, HasTheme, HasValidation, HasValue<AbstractField.ComponentValueChangeEvent<NumberField,Double>,Double>, HasValueAndElement<AbstractField.ComponentValueChangeEvent<NumberField,Double>,Double>, InputNotifier, KeyNotifier, HasAllowedCharPattern, HasClearButton, HasClientValidation, HasPrefix, HasSuffix, HasThemeVariant<TextFieldVariant>, HasTooltip, HasValidationProperties, InputField<AbstractField.ComponentValueChangeEvent<NumberField,Double>,Double>, HasAutocapitalize, HasAutocomplete, HasAutocorrect, HasPrefixAndSuffix, HasValidator<Double>, HasValueChangeMode, Serializable

@Tag("vaadin-number-field") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.5.5") @NpmPackage(value="@vaadin/number-field",version="24.5.5") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/number-field/src/vaadin-number-field.js") public class NumberField extends AbstractNumberField<NumberField,Double> implements HasAllowedCharPattern, HasThemeVariant<TextFieldVariant>
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.

Validation

Number Field 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 Double 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 NumberField.NumberFieldI18n 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 NumberField.NumberFieldI18n 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: