Class WLineEdit
- Direct Known Subclasses:
WAbstractSpinBox,WDateEdit,WPasswordEdit,WTimeEdit
To act upon text changes, connect a slot to the WFormWidget.changed() signal. This
signal is emitted when the user changed the content, and subsequently removes the focus from the
line edit.
To act upon editing, connect a slot to the WInteractWidget.keyWentUp() signal because
the WInteractWidget.keyPressed() signal is fired before the line edit has interpreted the
keypress to change its text.
At all times, the current content may be accessed with the getText() method.
You may specify a maximum length for the input using setMaxLength(). If you wish to provide more detailed input validation, you may set a validator
using the WFormWidget#setValidator()
method. Validators provide, in general, both client-side validation (as visual feed-back only)
and server-side validation when calling validate().
The widget corresponds to the HTML <input type="text"> or
<input type="password"> tag.
WLineEdit is an inline widget.
CSS
The emptyText style can be configured via .Wt-edit-emptyText, other styling can be done using inline or external CSS as appropriate.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData -
Field Summary
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_, noDefaultFields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS -
Constructor Summary
ConstructorsConstructorDescriptionCreates a line edit with empty content.WLineEdit(WContainerWidget parentContainer) Creates a line edit with empty content.Creates a line edit with given content.WLineEdit(String text, WContainerWidget parentContainer) Creates a line edit with given content. -
Method Summary
Modifier and TypeMethodDescriptionprotected intboxBorder(Orientation orientation) Returns the widget's built-in border width.protected intboxPadding(Orientation orientation) Returns the widget's built-in padding.Returns auto-completion support.intReturns the current cursor position.Returns the displayed text.protected voidgetDomChanges(List<DomElement> result, WApplication app) Get DOM changes for this widget.Deprecated.Returns the input mask.Returns inputMode support.intReturns the maximum length of text that can be entered.Returns the currently selected text.intReturns the current selection start.getText()Returns the current content.intReturns the current width of the line edit in number of characters.protected StringgetType()Returns the current value.booleanReturns whether there is selected text.booleanReturns if auto-completion support is not off.protected voidrender(EnumSet<RenderFlag> flags) Renders the widget.voidsetAutoComplete(boolean enabled) Sets (built-in browser) autocomplete support.voidsetAutoComplete(AutoCompleteMode token) Sets (built-in browser) autocomplete support.voidsetEchoMode(EchoMode echoMode) Deprecated.ForEchoMode.Password, useWPasswordEditinstead.protected voidsetFormData(WObject.FormData formData) final voidSets the input mask.final voidsetInputMask(String mask) Sets the input mask.final voidsetInputMask(String mask, InputMaskFlag flag, InputMaskFlag... flags) Sets the input mask.voidsetInputMask(String mask, EnumSet<InputMaskFlag> flags) Sets the input mask.voidsetInputMode(InputMode mode) Sets (built-in browser) input mode support.voidsetMaxLength(int chars) Specifies the maximum length of text that can be entered.voidsetSelection(int start, int length) Selects length characters starting from the start position.voidSets the content of the line edit.voidsetTextSize(int chars) Specifies the width of the line edit in number of characters.voidsetValueText(String value) Sets the current value.Event signal emitted when the text in the input field changed.validate()Validates the field.Methods inherited from class eu.webtoolkit.jwt.WFormWidget
changed, enableAjax, getLabel, getPlaceholderText, getRealValidator, getTabIndex, getValidator, hasValidatorChanged, isCanReceiveFocus, isReadOnly, propagateSetEnabled, refresh, remove, setEnabled, setHidden, setPlaceholderText, setReadOnly, setToolTip, setValidator, validated, validatorChangedMethods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggableMethods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, beingDeleted, blurred, callJavaScriptMember, childrenChanged, createDomElement, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, hideToolTip, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, iterateChildren, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, parentResized, propagateSetVisible, removeScript, removeStyleClass, resize, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFlexBox, setFloatSide, setFocus, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setVerticalAlignment, showToolTip, showToolTipOnHover, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemovedMethods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, layoutSizeChanged, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, removeWidget, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, trMethods inherited from class eu.webtoolkit.jwt.WObject
getObjectName
-
Constructor Details
-
WLineEdit
Creates a line edit with empty content. -
WLineEdit
public WLineEdit()Creates a line edit with empty content. -
WLineEdit
Creates a line edit with given content. -
WLineEdit
Creates a line edit with given content.
-
-
Method Details
-
setTextSize
public void setTextSize(int chars) Specifies the width of the line edit in number of characters.This specifies the width of the line edit that is roughly equivalent with
charscharacters. This does not limit the maximum length of a string that may be entered, which may be set usingsetMaxLength().The default value is 10.
-
getTextSize
public int getTextSize()Returns the current width of the line edit in number of characters.- See Also:
-
setText
Sets the content of the line edit.The default value is "".
- See Also:
-
getText
Returns the current content.- See Also:
-
getDisplayText
Returns the displayed text.If
getEchoMode()is set to Normal, and no input mask is defined, this returns the same asgetText().If an input mask is defined, then the text is returned including space characters.
If
getEchoMode()is set to Password, then a string of asterisks is returned equal to the length of the text.- See Also:
-
setMaxLength
public void setMaxLength(int chars) Specifies the maximum length of text that can be entered.A value <= 0 indicates that there is no limit.
The default value is -1.
-
getMaxLength
public int getMaxLength()Returns the maximum length of text that can be entered.- See Also:
-
setEchoMode
Deprecated.ForEchoMode.Password, useWPasswordEditinstead.Sets the echo mode.The default echo mode is Normal.
-
getEchoMode
Deprecated.ForEchoMode.Password, useWPasswordEditinstead.Returns the echo mode.- See Also:
-
setAutoComplete
public void setAutoComplete(boolean enabled) Sets (built-in browser) autocomplete support.Depending on the user agent, this may assist the user in filling in text for common input fields (e.g. address information) based on some heuristics.
The default value is
true. -
setAutoComplete
Sets (built-in browser) autocomplete support.Depending on the user agent, this may assist the user in filling in text for common input fields (e.g. address information) based on some heuristics.
The default value is
AutoCompleteMode.On. -
isAutoComplete
public boolean isAutoComplete()Returns if auto-completion support is not off.- See Also:
-
getAutoCompleteToken
Returns auto-completion support.- See Also:
-
setInputMode
Sets (built-in browser) input mode support.The input mode suggest what type of virtual keyboard should be used when applicable (mainly for phone users).
When
InputMode.Offis used, the inputmode field is not specified. Not to be confused withInputMode.None, which suggest the browser to not use any virtual keybord.The default value is
InputMode.Off. -
getInputMode
Returns inputMode support.- See Also:
-
getSelectionStart
public int getSelectionStart()Returns the current selection start.Returns -1 if there is no selected text.
- See Also:
-
getSelectedText
Returns the currently selected text.Returns an empty string if there is currently no selected text.
- See Also:
-
hasSelectedText
public boolean hasSelectedText()Returns whether there is selected text. -
setSelection
public void setSelection(int start, int length) Selects length characters starting from the start position. -
getCursorPosition
public int getCursorPosition()Returns the current cursor position.Returns -1 if the widget does not have the focus.
-
getValueText
Returns the current value.Returns
getText().- Specified by:
getValueTextin classWFormWidget
-
setValueText
Sets the current value.Calls
setText().- Specified by:
setValueTextin classWFormWidget
-
getInputMask
Returns the input mask.- See Also:
-
setInputMask
Sets the input mask.If no input mask is supplied, or the given input mask is empty, no input mask is applied.
The following characters can be used in the input mask:
The distinction between required and optional characters won't be apparent on the client side, but will affect the result ofCharacter Description A ASCII alphabetic character: A-Z, a-z (required) a ASCII alphabetic character: A-Z, a-z (optional) N ASCII alphanumeric character: A-Z, a-z, 0-9 (required) n ASCII alphanumeric character: A-Z, a-z, 0-9 (optional) X Any character (required) x Any character (optional) 9 Digit: 0-9 (required) 0 Digit: 0-9 (optional) D Nonzero digit: 1-9 (required) d Nonzero digit: 1-9 (optional) # Digit or sign: 0-9, -, + (required) H Hexadecimal character: A-F, a-f, 0-9 (required) h Hexadecimal character: A-F, a-f, 0-9 (optional) B Binary digit: 0-1 (required) b Binary digit: 0-1 (optional) validate().There are also a few special characters, that won't be checked against, but modify the value in some way:
A backslash ('\') can be used to escape any of the mask characters or modifiers, so that they can be used verbatim in the input mask.Character Description > The following characters are uppercased < The following characters are lowercased ! The casing of the following characters remains the same If the mask ends with a semicolon (';') followed by a character, this character will be used on the client side to display spaces. This defaults to the space (' ') character. The space character will be removed from the value of this WLineEdit.
Examples:
Input mask Notes 009.009.009.009;_
IP address. Spaces are denoted by '_'. Will validate if there is at least one digit per segment. 9999-99-99
Date, in yyyy-MM-dd notation. Spaces are denoted by ' '. Will validate if all digits are filled in. >HH:HH:HH:HH:HH:HH;_
MAC address. Spaces are denoted by '_'. Will validate if all hexadecimal characters are filled in. All characters will be formatted in uppercase. Input masks are enforced by JavaScript on the client side. Without JavaScript or using
setText(), however, non-compliant strings can be entered. This does not result in an error: any non-compliant characters will be removed from the input and this action will be logged. -
setInputMask
Sets the input mask. -
setInputMask
public final void setInputMask()Sets the input mask. -
setInputMask
Sets the input mask.Calls
setInputMask(mask, EnumSet.noneOf(InputMaskFlag.class)) -
validate
Description copied from class:WFormWidgetValidates the field.- Overrides:
validatein classWFormWidget- See Also:
-
textInput
Event signal emitted when the text in the input field changed.This signal is emitted whenever the text contents has changed. Unlike the
WFormWidget.changed()signal, the signal is fired on every change, not only when the focus is lost. Unlike theWInteractWidget.keyPressed()signal, this signal is fired also for other events that change the text, such as paste actions.- See Also:
-
getDomChanges
Description copied from class:WWebWidgetGet DOM changes for this widget.This is an internal function, and should not be called directly, or be overridden!
- Overrides:
getDomChangesin classWWebWidget
-
setFormData
- Overrides:
setFormDatain classWObject
-
boxPadding
Description copied from class:WWidgetReturns the widget's built-in padding.This is used by the layout managers to correct for a built-in padding which interferes with setting a widget's width (or height) to 100%.
A layout manager needs to set the width to 100% only for form widgets (
WTextArea,WLineEdit,WComboBox, etc...). Therefore, only for those widgets this needs to return the padding (the default implementation returns 0).For form widgets, the padding depends on the specific browser/platform combination, unless an explicit padding is set for the widget.
When setting an explicit padding for the widget using a style class, you will want to reimplement this method to return this padding in case you want to set the widget inside a layout manager.
- Overrides:
boxPaddingin classWWidget- See Also:
-
boxBorder
Description copied from class:WWidgetReturns the widget's built-in border width.This is used by the layout managers to correct for a built-in border which interferes with setting a widget's width (or height) to 100%.
A layout manager needs to set the width to 100% only for form widgets (
WTextArea,WLineEdit,WComboBox, etc...). Therefore, only for those widgets this needs to return the border width (the default implementation returns 0).For form widgets, the border width depends on the specific browser/platform combination, unless an explicit border is set for the widget.
When setting an explicit border for the widget using a style class, you will want to reimplement this method to return this border width, in case you want to set the widget inside a layout manager.
-
render
Description copied from class:WWidgetRenders the widget.This function renders the widget (or an update for the widget), after this has been scheduled using
scheduleRender().The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.
- Overrides:
renderin classWFormWidget
-
getType
-
EchoMode.Password, useWPasswordEditinstead.