A widget that provides a single line edit. More...
#include <Wt/WLineEdit>

Public Types | |
| enum | EchoMode { Normal, Password } |
| Enumeration that describes how the contents is displayed. More... | |
| enum | InputMaskFlag { KeepMaskWhileBlurred = 0x1 } |
| Enumeration that describes options for input masks. More... | |
Public Member Functions | |
| WLineEdit (WContainerWidget *parent=0) | |
| Creates a line edit with empty content and optional parent. | |
| WLineEdit (const WString &content, WContainerWidget *parent=0) | |
| Creates a line edit with given content and optional parent. | |
| void | setTextSize (int chars) |
| Specifies the width of the line edit in number of characters. | |
| int | textSize () const |
| Returns the current width of the line edit in number of characters. | |
| virtual void | setText (const WString &text) |
| Sets the content of the line edit. | |
| const WString & | text () const |
| Returns the current content. | |
| WString | displayText () const |
| Returns the displayed text. | |
| void | setMaxLength (int length) |
| Specifies the maximum length of text that can be entered. | |
| int | maxLength () const |
| Returns the maximum length of text that can be entered. | |
| void | setEchoMode (EchoMode echoMode) |
| Sets the echo mode. | |
| EchoMode | echoMode () const |
| Returns the echo mode. | |
| void | setAutoComplete (bool enabled) |
| Sets (built-in browser) autocomplete support. | |
| bool | autoComplete () const |
| Returns auto-completion support. | |
| int | selectionStart () const |
| Returns the current selection start. | |
| WString | selectedText () const |
| Returns the currently selected text. | |
| bool | hasSelectedText () const |
| Returns whether there is selected text. | |
| void | setSelection (int start, int length) |
| Selects length characters starting from the start position. | |
| int | cursorPosition () const |
| Returns the current cursor position. | |
| virtual WString | valueText () const |
| Returns the current value. | |
| virtual void | setValueText (const WString &value) |
| Sets the current value. | |
| WString | inputMask () const |
| Returns the input mask. | |
| void | setInputMask (const WString &mask="", WFlags< InputMaskFlag > flags=0) |
| Sets the input mask. | |
| virtual WValidator::State | validate () |
| Validates the field. | |
| EventSignal & | textInput () |
| Event signal emitted when the text in the input field changed. | |
Protected Member Functions | |
| virtual int | boxPadding (Orientation orientation) const |
| Returns the widget's built-in padding. | |
| virtual int | boxBorder (Orientation orientation) const |
| Returns the widget's built-in border width. | |
| virtual void | render (WFlags< RenderFlag > flags) |
| Renders the widget. | |
A widget that provides a single line edit.
To act upon text changes, connect a slot to the 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 keyWentUp() signal because the 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 text() 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 setValidator(WValidator *) method. Validators provide, in general, both client-side validation (as visual feed-back only) and server-side validation when calling validate().
Usage example:
Wt::WContainerWidget *w = new Wt::WContainerWidget(); Wt::WLabel *label = new Wt::WLabel("Age:", w); Wt::WLineEdit *edit = new Wt::WLineEdit("13", w); edit->setValidator(new Wt::WIntValidator(0, 200)); label->setBuddy(edit);
The widget corresponds to the HTML <input type="text"> or <input type="password"> tag.
WLineEdit is an inline widget.
The emptyText style can be configured via .Wt-edit-emptyText, other styling can be done using inline or external CSS as appropriate.
Enumeration that describes how the contents is displayed.
Enumeration that describes options for input masks.
| bool Wt::WLineEdit::autoComplete | ( | ) | const |
Returns auto-completion support.
| int Wt::WLineEdit::boxBorder | ( | Orientation | orientation | ) | const [protected, virtual] |
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.
Reimplemented from Wt::WWidget.
| int Wt::WLineEdit::boxPadding | ( | Orientation | orientation | ) | const [protected, virtual] |
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.
Reimplemented from Wt::WWidget.
Reimplemented in Wt::WAbstractSpinBox.
| int Wt::WLineEdit::cursorPosition | ( | ) | const |
Returns the current cursor position.
Returns -1 if the widget does not have the focus.
| WString Wt::WLineEdit::displayText | ( | ) | const |
Returns the displayed text.
If echoMode() is set to Normal, and no input mask is defined, this returns the same as text().
If an input mask is defined, then the text is returned including space characters.
If echoMode() is set to Password, then a string of asterisks is returned equal to the length of the text.
| EchoMode Wt::WLineEdit::echoMode | ( | ) | const |
Returns the echo mode.
| bool Wt::WLineEdit::hasSelectedText | ( | ) | const |
Returns whether there is selected text.
| WString Wt::WLineEdit::inputMask | ( | ) | const |
Returns the input mask.
| int Wt::WLineEdit::maxLength | ( | ) | const |
Returns the maximum length of text that can be entered.
| void Wt::WLineEdit::render | ( | WFlags< RenderFlag > | flags | ) | [protected, virtual] |
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.
Reimplemented from Wt::WFormWidget.
Reimplemented in Wt::WDateEdit, Wt::WDoubleSpinBox, Wt::WAbstractSpinBox, and Wt::WTimeEdit.
| WString Wt::WLineEdit::selectedText | ( | ) | const |
Returns the currently selected text.
Returns an empty string if there is currently no selected text.
| int Wt::WLineEdit::selectionStart | ( | ) | const |
Returns the current selection start.
Returns -1 if there is no selected text.
| void Wt::WLineEdit::setAutoComplete | ( | bool | 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.
| void Wt::WLineEdit::setEchoMode | ( | EchoMode | echoMode | ) |
Sets the echo mode.
The default echo mode is Normal.
| void Wt::WLineEdit::setInputMask | ( | const WString & | mask = "", |
| WFlags< InputMaskFlag > | flags = 0 |
||
| ) |
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) |
The distinction between required and optional characters won't be apparent on the client side, but will affect the result of 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 |
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.
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.
| void Wt::WLineEdit::setMaxLength | ( | int | length | ) |
Specifies the maximum length of text that can be entered.
A value <= 0 indicates that there is no limit.
The default value is -1.
| void Wt::WLineEdit::setSelection | ( | int | start, |
| int | length | ||
| ) |
Selects length characters starting from the start position.
| void Wt::WLineEdit::setText | ( | const WString & | text | ) | [virtual] |
Sets the content of the line edit.
The default value is "".
Reimplemented in Wt::WTimeEdit, and Wt::WAbstractSpinBox.
| void Wt::WLineEdit::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 using setMaxLength(int).
The default value is 10.
| void Wt::WLineEdit::setValueText | ( | const WString & | value | ) | [virtual] |
| const WString& Wt::WLineEdit::text | ( | ) | const |
Returns the current content.
Event signal emitted when the text in the input field changed.
This signal is emitted whenever the text contents has changed. Unlike the changed() signal, the signal is fired on every change, not only when the focus is lost. Unlike the keyPressed() signal, this signal is fired also for other events that change the text, such as paste actions.
| int Wt::WLineEdit::textSize | ( | ) | const |
Returns the current width of the line edit in number of characters.
| WValidator::State Wt::WLineEdit::validate | ( | ) | [virtual] |
Validates the field.
Reimplemented from Wt::WFormWidget.
Reimplemented in Wt::WAbstractSpinBox.
| WString Wt::WLineEdit::valueText | ( | ) | const [virtual] |
1.7.6.1