Class WLineEdit
- Direct Known Subclasses:
WAbstractSpinBox
,WDateEdit
,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_
-
Constructor Summary
ConstructorDescriptionCreates 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 int
boxBorder
(Orientation orientation) Returns the widget's built-in border width.protected int
boxPadding
(Orientation orientation) Returns the widget's built-in padding.int
Returns the current cursor position.Returns the displayed text.protected void
getDomChanges
(List<DomElement> result, WApplication app) Get DOM changes for this widget.Returns the echo mode.Returns the input mask.int
Returns the maximum length of text that can be entered.Returns the currently selected text.int
Returns the current selection start.getText()
Returns the current content.int
Returns the current width of the line edit in number of characters.Returns the current value.boolean
Returns whether there is selected text.boolean
Returns auto-completion support.protected void
render
(EnumSet<RenderFlag> flags) Renders the widget.void
setAutoComplete
(boolean enabled) Sets (built-in browser) autocomplete support.void
setEchoMode
(EchoMode echoMode) Sets the echo mode.protected void
setFormData
(WObject.FormData formData) final void
Sets the input mask.final void
setInputMask
(String mask) Sets the input mask.final void
setInputMask
(String mask, InputMaskFlag flag, InputMaskFlag... flags) Sets the input mask.void
setInputMask
(String mask, EnumSet<InputMaskFlag> flags) Sets the input mask.void
setMaxLength
(int chars) Specifies the maximum length of text that can be entered.void
setSelection
(int start, int length) Selects length characters starting from the start position.void
Sets the content of the line edit.void
setTextSize
(int chars) Specifies the width of the line edit in number of characters.void
setValueText
(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, getTabIndex, getValidator, isCanReceiveFocus, isReadOnly, propagateSetEnabled, refresh, remove, setEnabled, setHidden, setPlaceholderText, setReadOnly, setToolTip, setValidator, validated, validatorChanged
Methods 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, unsetDraggable
Methods 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, 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, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemoved
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, layoutSizeChanged, needsRerender, positionAt, positionAt, removeFromParent, removeStyleClass, removeWidget, render, resize, scheduleRender, scheduleRender, scheduleRender, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
Methods 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
chars
characters. 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
Sets the echo mode.The default echo mode is Normal.
-
getEchoMode
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
. -
isAutoComplete
public boolean isAutoComplete()Returns auto-completion 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:
getValueText
in classWFormWidget
-
setValueText
Sets the current value.Calls
setText()
.- Specified by:
setValueText
in 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:
Character 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:
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:WFormWidget
Validates the field.- Overrides:
validate
in 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. -
getDomChanges
Description copied from class:WWebWidget
Get DOM changes for this widget.This is an internal function, and should not be called directly, or be overridden!
- Overrides:
getDomChanges
in classWWebWidget
-
setFormData
- Overrides:
setFormData
in classWObject
-
boxPadding
Description copied from class:WWidget
Returns 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:
boxPadding
in classWWidget
- See Also:
-
boxBorder
Description copied from class:WWidget
Returns 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:WWidget
Renders 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:
render
in classWFormWidget
-