Class TextField

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<C,T>
com.vaadin.flow.component.AbstractSinglePropertyField<TComponent,TValue>
com.vaadin.flow.component.textfield.TextFieldBase<TextField,String>
com.vaadin.flow.component.textfield.TextField
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<TextField>, com.vaadin.flow.component.CompositionNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<TextField>, com.vaadin.flow.component.FocusNotifier<TextField>, 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<TextField,String>,String>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>,String>, com.vaadin.flow.component.InputNotifier, com.vaadin.flow.component.KeyNotifier, HasAllowedCharPattern, HasClearButton, HasClientValidation, HasPrefix, HasSuffix, HasThemeVariant<TextFieldVariant>, HasTooltip, HasValidationProperties, InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>,String>, HasAutocapitalize, HasAutocomplete, HasAutocorrect, HasPrefixAndSuffix, com.vaadin.flow.data.binder.HasValidator<String>, com.vaadin.flow.data.value.HasValueChangeMode, Serializable

@Tag("vaadin-text-field") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.4.5") @NpmPackage(value="@vaadin/text-field",version="24.4.5") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/text-field/src/vaadin-text-field.js") public class TextField extends TextFieldBase<TextField,String> implements HasAllowedCharPattern, HasThemeVariant<TextFieldVariant>
Text Field allows the user to input and edit text. Prefix and suffix components, such as icons, are also supported.
Author:
Vaadin Ltd
See Also:
  • Nested Class Summary

    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 extends Object>

    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

    HasClientValidation.ClientValidatedEvent

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

    com.vaadin.flow.component.HasValue.ValueChangeEvent<V extends Object>, 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 TextField.
    TextField(com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>> listener)
    Constructs an empty TextField with a value change listener.
    Constructs an empty TextField with the given label.
    TextField(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>> listener)
    Constructs an empty TextField with a label and a value change listener.
    TextField(String label, String placeholder)
    Constructs an empty TextField with the given label and placeholder text.
    TextField(String label, String initialValue, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>> listener)
    Constructs an empty TextField with a label,a value change listener and an initial value.
    TextField(String label, String initialValue, String placeholder)
    Constructs a TextField with the given label, an initial value and placeholder text.
  • Method Summary

    Modifier and Type
    Method
    Description
    com.vaadin.flow.data.binder.Validator<String>
     
     
    int
    Maximum number of characters (in Unicode code points) that the user can enter.
    int
    Minimum number of characters (in Unicode code points) that the user can enter.
    A regular expression that the value is checked against.
    Returns the current value of the text field.
    protected void
    onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
     
    void
    setManualValidation(boolean enabled)
     
    void
    setMaxLength(int maxLength)
    Maximum number of characters (in Unicode code points) that the user can enter.
    void
    setMinLength(int minLength)
    Minimum number of characters (in Unicode code points) that the user can enter.
    void
    setPattern(String pattern)
    Sets a regular expression for the value to pass on the client-side.
    void
    setRequired(boolean required)
    Specifies that the user must fill in a value.
    void
    setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
     
    void
    Sets the value of this text field.
    protected void
    Performs server-side validation of the current value and the validation constraints of the field, such as setPattern(String).

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

    getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEvent

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

    addValueChangeListener, isEmpty, setModelValue, 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.shared.HasAllowedCharPattern

    getAllowedCharPattern, setAllowedCharPattern

    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, setErrorMessage, setInvalid

    Methods inherited from interface com.vaadin.flow.data.binder.HasValidator

    addValidationStatusChangeListener

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

    addValueChangeListener, clear, getOptionalValue, isEmpty

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

    isReadOnly, isRequiredIndicatorVisible, 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

    • TextField

      public TextField()
      Constructs an empty TextField.
    • TextField

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

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

      public TextField(String label, String initialValue, String placeholder)
      Constructs a TextField with the given label, an initial value and placeholder text.
      Parameters:
      label - the text to set as the label
      initialValue - the initial value
      placeholder - the placeholder text to set
      See Also:
      • AbstractField.setValue(Object)
      • HasPlaceholder.setPlaceholder(String)
    • TextField

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

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

      public TextField(String label, String initialValue, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>> listener)
      Constructs an empty TextField with a label,a value change listener 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)
      • AbstractField.setValue(Object)
      • AbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)
  • Method Details

    • setMaxLength

      public void setMaxLength(int maxLength)
      Maximum number of characters (in Unicode code points) that the user can enter.
      Parameters:
      maxLength - the maximum length
    • getMaxLength

      public int getMaxLength()
      Maximum number of characters (in Unicode code points) that the user can enter.
      Returns:
      the maxlength property from the webcomponent
    • setMinLength

      public void setMinLength(int minLength)
      Minimum number of characters (in Unicode code points) that the user can enter.
      Parameters:
      minLength - the minimum length
    • getMinLength

      public int getMinLength()
      Minimum number of characters (in Unicode code points) that the user can enter.
      Returns:
      the minlength property from the webcomponent
    • setRequired

      public void setRequired(boolean required)

      Specifies that the user must fill in a value.

      NOTE: The required indicator will not be visible, if there is no label property set for the textfield.
      Overrides:
      setRequired in class TextFieldBase<TextField,String>
      Parameters:
      required - the boolean value to set
    • setPattern

      public void setPattern(String pattern)
      Sets a regular expression for the value to pass on the client-side. The pattern must be a valid JavaScript Regular Expression that matches the entire value, not just some subset.
      Parameters:
      pattern - the new String pattern
      See Also:
    • getPattern

      public String getPattern()
      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
    • getEmptyValue

      public String getEmptyValue()
      Specified by:
      getEmptyValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>,String>
      Overrides:
      getEmptyValue in class com.vaadin.flow.component.AbstractField<TextField,String>
    • setValue

      public void setValue(String value)
      Sets the value of this text field. If the new value is not equal to getValue(), fires a value change event. Throws NullPointerException, if the value is null.

      Note: Binder will take care of the null conversion when integrates with text field, as long as no new converter is defined.

      Specified by:
      setValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>,String>
      Overrides:
      setValue in class com.vaadin.flow.component.AbstractField<TextField,String>
      Parameters:
      value - the new value, not null
    • getValue

      public String getValue()
      Returns the current value of the text field. By default, the empty text field will return an empty string.
      Specified by:
      getValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>,String>
      Overrides:
      getValue in class com.vaadin.flow.component.AbstractField<TextField,String>
      Returns:
      the current value.
    • setRequiredIndicatorVisible

      public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
      Specified by:
      setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>,String>
      Specified by:
      setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>,String>
    • getDefaultValidator

      public com.vaadin.flow.data.binder.Validator<String> getDefaultValidator()
      Specified by:
      getDefaultValidator in interface com.vaadin.flow.data.binder.HasValidator<String>
    • setManualValidation

      public void setManualValidation(boolean enabled)
      Specified by:
      setManualValidation in interface com.vaadin.flow.component.HasValidation
    • validate

      protected void validate()
      Performs server-side validation of the current value and the validation constraints of the field, such as setPattern(String). This is needed because it is possible to circumvent the client-side validation constraints using browser development tools.
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component