Wt  3.3.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator
Public Types | Public Member Functions | Protected Member Functions
Wt::WLineEdit Class Reference

A widget that provides a single line edit. More...

#include <Wt/WLineEdit>

Inheritance diagram for Wt::WLineEdit:
Inheritance graph
[legend]

List of all members.

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 WStringtext () 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.
EventSignaltextInput ()
 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.

Detailed Description

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.

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:
WTextArea

Member Enumeration Documentation

Enumeration that describes how the contents is displayed.

See also:
setEchoMode(EchoMode)
Enumerator:
Normal 

Characters are shown.

Password 

Hide the contents as for a password.

Enumeration that describes options for input masks.

See also:
setInputMask()
Enumerator:
KeepMaskWhileBlurred 

Keep the input mask when blurred.


Member Function Documentation

Returns auto-completion support.

See also:
setAutoComplete()
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.

See also:
boxPadding()

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.

See also:
boxBorder()

Reimplemented from Wt::WWidget.

Reimplemented in Wt::WAbstractSpinBox.

Returns the current cursor position.

Returns -1 if the widget does not have the focus.

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.

See also:
setText()

Returns the echo mode.

See also:
setEchoMode(EchoMode)

Returns whether there is selected text.

See also:
selectedtext()

Returns the input mask.

See also:
setInputMask()
int Wt::WLineEdit::maxLength ( ) const

Returns the maximum length of text that can be entered.

See also:
setMaxLength(int)
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.

Returns the currently selected text.

Returns an empty string if there is currently no selected text.

See also:
hasSelectedText()

Returns the current selection start.

Returns -1 if there is no selected text.

See also:
hasSelectedText(), selectedText()
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.

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)
XAny character (required)
xAny character (optional)
9Digit: 0-9 (required)
0Digit: 0-9 (optional)
DNonzero digit: 1-9 (required)
dNonzero 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)
BBinary digit: 0-1 (required)
bBinary 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:

CharacterDescription
>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 maskNotes
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.

See also:
selectedtext()
void Wt::WLineEdit::setText ( const WString text) [virtual]

Sets the content of the line edit.

The default value is "".

See also:
text()

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]

Sets the current value.

Calls setText().

Implements Wt::WFormWidget.

const WString& Wt::WLineEdit::text ( ) const

Returns the current content.

See also:
setText()

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.

See also:
keyPressed(), changed()
int Wt::WLineEdit::textSize ( ) const

Returns the current width of the line edit in number of characters.

See also:
setTextSize(int)

Validates the field.

See also:
validated()

Reimplemented from Wt::WFormWidget.

Reimplemented in Wt::WAbstractSpinBox.

WString Wt::WLineEdit::valueText ( ) const [virtual]

Returns the current value.

Returns text().

Implements Wt::WFormWidget.

 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator

Generated on Tue Mar 22 2016 for the C++ Web Toolkit (Wt) by doxygen 1.7.6.1