Class TextField

    • Constructor Detail

      • 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), 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:
        setLabel(String), AbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)
      • 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:
        setLabel(String), AbstractField.setValue(Object), AbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)
    • Method Detail

      • getValueChangeMode

        public com.vaadin.flow.data.value.ValueChangeMode getValueChangeMode()

        The default value is ValueChangeMode.ON_CHANGE.

        Specified by:
        getValueChangeMode in interface com.vaadin.flow.data.value.HasValueChangeMode
      • setValueChangeMode

        public void setValueChangeMode​(com.vaadin.flow.data.value.ValueChangeMode valueChangeMode)
        Specified by:
        setValueChangeMode in interface com.vaadin.flow.data.value.HasValueChangeMode
      • setValueChangeTimeout

        public void setValueChangeTimeout​(int valueChangeTimeout)
        Specified by:
        setValueChangeTimeout in interface com.vaadin.flow.data.value.HasValueChangeMode
      • getValueChangeTimeout

        public int getValueChangeTimeout()
        Specified by:
        getValueChangeTimeout in interface com.vaadin.flow.data.value.HasValueChangeMode
      • getErrorMessage

        public String getErrorMessage()
        Specified by:
        getErrorMessage in interface com.vaadin.flow.component.HasValidation
      • setErrorMessage

        public void setErrorMessage​(String errorMessage)
        Description copied from class: GeneratedVaadinTextField

        Description copied from corresponding location in WebComponent:

        Error to show when the input value is invalid.

        Specified by:
        setErrorMessage in interface com.vaadin.flow.component.HasValidation
        Overrides:
        setErrorMessage in class GeneratedVaadinTextField<TextField,​String>
        Parameters:
        errorMessage - the String value to set
      • isInvalid

        public boolean isInvalid()
        Specified by:
        isInvalid in interface com.vaadin.flow.component.HasValidation
      • setInvalid

        public void setInvalid​(boolean invalid)
        Description copied from class: GeneratedVaadinTextField

        Description copied from corresponding location in WebComponent:

        This property is set to true when the control value is invalid.

        Specified by:
        setInvalid in interface com.vaadin.flow.component.HasValidation
        Overrides:
        setInvalid in class GeneratedVaadinTextField<TextField,​String>
        Parameters:
        invalid - the boolean value to set
      • setLabel

        public void setLabel​(String label)
        Description copied from class: GeneratedVaadinTextField

        Description copied from corresponding location in WebComponent:

        String used for the label element.

        Specified by:
        setLabel in interface com.vaadin.flow.component.HasLabel
        Overrides:
        setLabel in class GeneratedVaadinTextField<TextField,​String>
        Parameters:
        label - the String value to set
      • getLabel

        public String getLabel()
        String used for the label element.
        Specified by:
        getLabel in interface com.vaadin.flow.component.HasLabel
        Returns:
        the label property from the webcomponent
      • getPlaceholder

        public String getPlaceholder()
        A hint to the user of what can be entered in the component.
        Returns:
        the placeholder property from the webcomponent
      • isAutoselect

        public boolean isAutoselect()
        Specifies if the field value gets automatically selected when the field gains focus.
        Returns:
        true if autoselect is active, false otherwise
      • setAutoselect

        public void setAutoselect​(boolean autoselect)
        Set to true to always have the field value automatically selected when the field gains focus, false otherwise.
        Overrides:
        setAutoselect in class GeneratedVaadinTextField<TextField,​String>
        Parameters:
        autoselect - true to set auto select on, false otherwise
      • setAutofocus

        public void setAutofocus​(boolean autofocus)
        Description copied from class: GeneratedVaadinTextField

        Description copied from corresponding location in WebComponent:

        Specify that this control should have input focus when the page loads.

        Overrides:
        setAutofocus in class GeneratedVaadinTextField<TextField,​String>
        Parameters:
        autofocus - the boolean value to set
      • isAutofocus

        public boolean isAutofocus()
        Specify that this control should have input focus when the page loads.
        Returns:
        the autofocus property from the webcomponent
      • 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
      • isRequired

        public boolean isRequired()
        Specifies that the user must fill in a value.
        Returns:
        the required 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 GeneratedVaadinTextField<TextField,​String>
        Parameters:
        required - the boolean value to set
      • isPreventInvalidInput

        @Deprecated
        public boolean isPreventInvalidInput()
        Deprecated.
        Since 23.2, this API is deprecated.
        When set to true, user is prevented from typing a value that conflicts with the given pattern.
        Returns:
        the preventInvalidInput property from the webcomponent
      • 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
      • getTitle

        public String getTitle()
        The text usually displayed in a tooltip popup when the mouse is over the field.
        Returns:
        the title 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>
      • addValidationStatusChangeListener

        public com.vaadin.flow.shared.Registration addValidationStatusChangeListener​(com.vaadin.flow.data.binder.ValidationStatusChangeListener<String> listener)
        Specified by:
        addValidationStatusChangeListener in interface com.vaadin.flow.data.binder.HasValidator<String>
      • 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.
        Overrides:
        validate in class GeneratedVaadinTextField<TextField,​String>
      • onAttach

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

        protected boolean isFeatureFlagEnabled​(com.vaadin.experimental.Feature feature)
        Returns true if the given feature flag is enabled, false otherwise.

        Exposed with protected visibility to support mocking

        The method requires the VaadinService instance to obtain the available feature flags, otherwise, the feature is considered disabled.

        Parameters:
        feature - the feature flag.
        Returns:
        whether the feature flag is enabled.