public class TextField extends GeneratedVaadinTextField<TextField,String> implements com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasValidation, com.vaadin.flow.data.value.HasValueChangeMode, HasPrefixAndSuffix, com.vaadin.flow.component.InputNotifier, com.vaadin.flow.component.KeyNotifier, com.vaadin.flow.component.CompositionNotifier, HasAutocomplete, HasAutocapitalize, HasAutocorrect, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.data.binder.HasValidator<String>, HasClientValidation
vaadin-text-field element.GeneratedVaadinTextField.ChangeEvent<R extends GeneratedVaadinTextField<R,?>>, GeneratedVaadinTextField.InvalidChangeEvent<R extends GeneratedVaadinTextField<R,?>>com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V>HasClientValidation.ClientValidatedEventcom.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>DEFAULT_CHANGE_TIMEOUTAUTOCOMPLETE_ATTRIBUTEAUTOCAPITALIZE_ATTRIBUTEAUTOCORRECT_ATTRIBUTE| Constructor and Description |
|---|
TextField()
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. |
TextField(String label)
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. |
| Modifier and Type | Method and Description |
|---|---|
com.vaadin.flow.shared.Registration |
addValidationStatusChangeListener(com.vaadin.flow.data.binder.ValidationStatusChangeListener<String> listener) |
com.vaadin.flow.data.binder.Validator<String> |
getDefaultValidator() |
String |
getEmptyValue() |
String |
getErrorMessage() |
String |
getLabel()
String used for the label element.
|
int |
getMaxLength()
Maximum number of characters (in Unicode code points) that the user can
enter.
|
int |
getMinLength()
Minimum number of characters (in Unicode code points) that the user can
enter.
|
String |
getPattern()
A regular expression that the value is checked against.
|
String |
getPlaceholder()
A hint to the user of what can be entered in the component.
|
String |
getTitle()
The text usually displayed in a tooltip popup when the mouse is over the
field.
|
String |
getValue()
Returns the current value of the text field.
|
com.vaadin.flow.data.value.ValueChangeMode |
getValueChangeMode() |
int |
getValueChangeTimeout() |
boolean |
isAutofocus()
Specify that this control should have input focus when the page loads.
|
boolean |
isAutoselect()
Specifies if the field value gets automatically selected when the field
gains focus.
|
boolean |
isClearButtonVisible()
Gets the visibility state of the button which clears the text field.
|
protected boolean |
isEnforcedFieldValidationEnabled()
Whether the full experience validation is enforced for the component.
|
boolean |
isInvalid() |
boolean |
isPreventInvalidInput()
When set to
true, user is prevented from typing a value that
conflicts with the given pattern. |
boolean |
isRequired()
Specifies that the user must fill in a value.
|
protected void |
onAttach(com.vaadin.flow.component.AttachEvent attachEvent) |
void |
setAutofocus(boolean autofocus)
Description copied from corresponding location in WebComponent:
|
void |
setAutoselect(boolean autoselect)
Set to
true to always have the field value automatically
selected when the field gains focus, false otherwise. |
void |
setClearButtonVisible(boolean clearButtonVisible)
Set to
false to hide the clear button which clears the text
field. |
void |
setErrorMessage(String errorMessage)
Description copied from corresponding location in WebComponent:
|
void |
setInvalid(boolean invalid)
Description copied from corresponding location in WebComponent:
|
void |
setLabel(String label)
Sets the label for this component.
|
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)
Description copied from corresponding location in WebComponent:
|
void |
setPlaceholder(String placeholder)
Description copied from corresponding location in WebComponent:
|
void |
setPreventInvalidInput(boolean preventInvalidInput)
Description copied from corresponding location in WebComponent:
|
void |
setRequired(boolean required)
Specifies that the user must fill in a value.
|
void |
setRequiredIndicatorVisible(boolean requiredIndicatorVisible) |
void |
setTitle(String title)
Description copied from corresponding location in WebComponent:
|
void |
setValue(String value)
Sets the value of this text field.
|
void |
setValueChangeMode(com.vaadin.flow.data.value.ValueChangeMode valueChangeMode) |
void |
setValueChangeTimeout(int valueChangeTimeout) |
protected void |
validate()
Performs server-side validation of the current value and the validation
constraints of the field, such as
setPattern(String). |
addChangeListener, addInvalidChangeListener, addThemeVariants, addToInput, addToPrefix, addToSuffix, checkValidity, getAutocapitalizeString, getAutocompleteString, getAutocorrectString, getErrorMessageString, getLabelString, getListString, getMaxlengthDouble, getMinlengthDouble, getNameString, getPatternString, getPlaceholderString, getTitleString, isAutofocusBoolean, isAutoselectBoolean, isClearButtonVisibleBoolean, isDisabledBoolean, isInvalidBoolean, isPreventInvalidInputBoolean, isReadonlyBoolean, isRequiredBoolean, remove, removeAll, removeThemeVariants, setAutocapitalize, setAutocomplete, setAutocorrect, setDisabled, setList, setMaxlength, setMinlength, setName, setReadonlygetSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEventaddValueChangeListener, isEmpty, setModelValue, valueEqualsaddListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, set, setElement, setId, setVisibleclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullgetPrefixComponent, getSuffixComponent, setPrefixComponent, setSuffixComponentaddKeyDownListener, addKeyDownListener, addKeyPressListener, addKeyPressListener, addKeyUpListener, addKeyUpListeneraddCompositionEndListener, addCompositionStartListener, addCompositionUpdateListenergetAutocomplete, setAutocompletegetAutocapitalize, setAutocapitalizeisAutocorrect, setAutocorrectgetHelperComponent, getHelperText, setHelperComponent, setHelperTextaddClientValidatedEventListeneraddClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameaddFocusShortcut, blur, focus, getTabIndex, setTabIndexaddThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeNamepublic TextField()
TextField.public TextField(String label)
TextField with the given label.label - the text to set as the labelpublic TextField(String label, String placeholder)
TextField with the given label and
placeholder text.label - the text to set as the labelplaceholder - the placeholder text to setpublic TextField(String label, String initialValue, String placeholder)
TextField with the given label, an initial value and
placeholder text.label - the text to set as the labelinitialValue - the initial valueplaceholder - the placeholder text to setAbstractField.setValue(Object),
setPlaceholder(String)public TextField(com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>> listener)
TextField with a value change listener.listener - the value change listenerAbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)public TextField(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>> listener)
TextField with a label and a value change
listener.label - the text to set as the labellistener - the value change listenersetLabel(String),
AbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)public TextField(String label, String initialValue, com.vaadin.flow.component.HasValue.ValueChangeListener<? super com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>> listener)
TextField with a label,a value change
listener and an initial value.label - the text to set as the labelinitialValue - the initial valuelistener - the value change listenersetLabel(String),
AbstractField.setValue(Object),
AbstractField.addValueChangeListener(com.vaadin.flow.component.HasValue.ValueChangeListener)public com.vaadin.flow.data.value.ValueChangeMode getValueChangeMode()
The default value is ValueChangeMode.ON_CHANGE.
getValueChangeMode in interface com.vaadin.flow.data.value.HasValueChangeModepublic void setValueChangeMode(com.vaadin.flow.data.value.ValueChangeMode valueChangeMode)
setValueChangeMode in interface com.vaadin.flow.data.value.HasValueChangeModepublic void setValueChangeTimeout(int valueChangeTimeout)
setValueChangeTimeout in interface com.vaadin.flow.data.value.HasValueChangeModepublic int getValueChangeTimeout()
getValueChangeTimeout in interface com.vaadin.flow.data.value.HasValueChangeModepublic String getErrorMessage()
getErrorMessage in interface com.vaadin.flow.component.HasValidationpublic void setErrorMessage(String errorMessage)
GeneratedVaadinTextFieldDescription copied from corresponding location in WebComponent:
Error to show when the input value is invalid.
setErrorMessage in interface com.vaadin.flow.component.HasValidationsetErrorMessage in class GeneratedVaadinTextField<TextField,String>errorMessage - the String value to setpublic boolean isInvalid()
isInvalid in interface com.vaadin.flow.component.HasValidationpublic void setInvalid(boolean invalid)
GeneratedVaadinTextFieldDescription copied from corresponding location in WebComponent:
This property is set to true when the control value is invalid.
setInvalid in interface com.vaadin.flow.component.HasValidationsetInvalid in class GeneratedVaadinTextField<TextField,String>invalid - the boolean value to setpublic void setLabel(String label)
setLabel in interface com.vaadin.flow.component.HasLabelsetLabel in class GeneratedVaadinTextField<TextField,String>label - value for the label property in the webcomponentpublic String getLabel()
getLabel in interface com.vaadin.flow.component.HasLabellabel property from the webcomponentpublic void setPlaceholder(String placeholder)
GeneratedVaadinTextFieldDescription copied from corresponding location in WebComponent:
A hint to the user of what can be entered in the control.
setPlaceholder in class GeneratedVaadinTextField<TextField,String>placeholder - the String value to setpublic String getPlaceholder()
placeholder property from the webcomponentpublic boolean isAutoselect()
true if autoselect is active, false
otherwisepublic void setAutoselect(boolean autoselect)
true to always have the field value automatically
selected when the field gains focus, false otherwise.setAutoselect in class GeneratedVaadinTextField<TextField,String>autoselect - true to set auto select on, false
otherwisepublic boolean isClearButtonVisible()
true if the button is visible, false
otherwisepublic void setClearButtonVisible(boolean clearButtonVisible)
false to hide the clear button which clears the text
field.setClearButtonVisible in class GeneratedVaadinTextField<TextField,String>clearButtonVisible - true to set the button visible,
false otherwisepublic void setAutofocus(boolean autofocus)
GeneratedVaadinTextFieldDescription copied from corresponding location in WebComponent:
Specify that this control should have input focus when the page loads.
setAutofocus in class GeneratedVaadinTextField<TextField,String>autofocus - the boolean value to setpublic boolean isAutofocus()
autofocus property from the webcomponentpublic void setMaxLength(int maxLength)
maxLength - the maximum lengthpublic int getMaxLength()
maxlength property from the webcomponentpublic void setMinLength(int minLength)
minLength - the minimum lengthpublic int getMinLength()
minlength property from the webcomponentpublic boolean isRequired()
required property from the webcomponentpublic void setRequired(boolean required)
Specifies that the user must fill in a value.
NOTE: The required indicator will not be visible, if there is nolabel property set for the textfield.setRequired in class GeneratedVaadinTextField<TextField,String>required - the boolean value to setpublic boolean isPreventInvalidInput()
true, user is prevented from typing a value that
conflicts with the given pattern.preventInvalidInput property from the webcomponentpublic void setPreventInvalidInput(boolean preventInvalidInput)
GeneratedVaadinTextFieldDescription 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.
setPreventInvalidInput in class GeneratedVaadinTextField<TextField,String>preventInvalidInput - the boolean value to setpublic void setPattern(String pattern)
GeneratedVaadinTextFieldDescription 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.
setPattern in class GeneratedVaadinTextField<TextField,String>pattern - the String value to setpublic String getPattern()
pattern property from the webcomponentpublic String getTitle()
title property from the webcomponentpublic void setTitle(String title)
GeneratedVaadinTextFieldDescription copied from corresponding location in WebComponent:
The text usually displayed in a tooltip popup when the mouse is over the field.
setTitle in class GeneratedVaadinTextField<TextField,String>title - the String value to setpublic String getEmptyValue()
public void setValue(String value)
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.
public String getValue()
public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>,String>setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<TextField,String>,String>public com.vaadin.flow.data.binder.Validator<String> getDefaultValidator()
getDefaultValidator in interface com.vaadin.flow.data.binder.HasValidator<String>public com.vaadin.flow.shared.Registration addValidationStatusChangeListener(com.vaadin.flow.data.binder.ValidationStatusChangeListener<String> listener)
addValidationStatusChangeListener in interface com.vaadin.flow.data.binder.HasValidator<String>protected void validate()
setPattern(String). This is
needed because it is possible to circumvent the client-side validation
constraints using browser development tools.validate in class GeneratedVaadinTextField<TextField,String>protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
onAttach in class com.vaadin.flow.component.Componentprotected boolean isEnforcedFieldValidationEnabled()
Exposed with protected visibility to support mocking
The method requires the VaadinSession instance to obtain the
application configuration properties, otherwise, the feature is
considered disabled.
true if enabled, false otherwise.Copyright © 2025. All rights reserved.