Class WLineEdit

Direct Known Subclasses:
WAbstractSpinBox, WDateEdit, WTimeEdit

public class WLineEdit
extends WFormWidget
A widget that provides a single line edit.

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:
WTextArea
  • Constructor Details

  • 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 using setMaxLength().

      The default value is 10.

    • getTextSize

      public int getTextSize()
      Returns the current width of the line edit in number of characters.

      See Also:
      setTextSize(int chars)
    • setText

      public void setText​(java.lang.String text)
      Sets the content of the line edit.

      The default value is "".

      See Also:
      getText()
    • getText

      public java.lang.String getText()
      Returns the current content.

      See Also:
      setText(String text)
    • getDisplayText

      public java.lang.String getDisplayText()
      Returns the displayed text.

      If getEchoMode() is set to Normal, and no input mask is defined, this returns the same as getText().

      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:
      setText(String text)
    • 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:
      setMaxLength(int chars)
    • setEchoMode

      public void setEchoMode​(WLineEdit.EchoMode echoMode)
      Sets the echo mode.

      The default echo mode is Normal.

    • getEchoMode

      public WLineEdit.EchoMode getEchoMode()
      Returns the echo mode.

      See Also:
      setEchoMode(WLineEdit.EchoMode echoMode)
    • 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:
      setAutoComplete(boolean enabled)
    • getSelectionStart

      public int getSelectionStart()
      Returns the current selection start.

      Returns -1 if there is no selected text.

      See Also:
      hasSelectedText(), getSelectedText()
    • getSelectedText

      public java.lang.String getSelectedText()
      Returns the currently selected text.

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

      See Also:
      hasSelectedText()
    • 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

      public java.lang.String getValueText()
      Returns the current value.

      Returns getText().

      Specified by:
      getValueText in class WFormWidget
    • setValueText

      public void setValueText​(java.lang.String value)
      Sets the current value.

      Calls setText().

      Specified by:
      setValueText in class WFormWidget
    • getInputMask

      public java.lang.String getInputMask()
      Returns the input mask.

      See Also:
      setInputMask(String mask, EnumSet flags)
    • setInputMask

      public void setInputMask​(java.lang.String mask, java.util.EnumSet<WLineEdit.InputMaskFlag> flags)
      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.

    • setInputMask

      public final void setInputMask​(java.lang.String mask, WLineEdit.InputMaskFlag flag, WLineEdit.InputMaskFlag... flags)
    • setInputMask

      public final void setInputMask()
    • setInputMask

      public final void setInputMask​(java.lang.String mask)
    • validate

      public WValidator.State validate()
      Description copied from class: WFormWidget
      Validates the field.

      Overrides:
      validate in class WFormWidget
      See Also:
      WFormWidget.validated()
    • textInput

      public EventSignal 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 the WInteractWidget.keyPressed() signal, this signal is fired also for other events that change the text, such as paste actions.

      See Also:
      WInteractWidget.keyPressed(), WFormWidget.changed()
    • getDomChanges

      protected void getDomChanges​(java.util.List<DomElement> result, WApplication app)
      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 class WWebWidget
    • setFormData

      protected void setFormData​(WObject.FormData formData)
      Overrides:
      setFormData in class WObject
    • boxPadding

      protected int boxPadding​(Orientation orientation)
      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 class WWidget
      See Also:
      WWidget.boxBorder(Orientation orientation)
    • boxBorder

      protected int boxBorder​(Orientation orientation)
      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.

      Overrides:
      boxBorder in class WWidget
      See Also:
      WWidget.boxPadding(Orientation orientation)
    • render

      protected void render​(java.util.EnumSet<RenderFlag> flags)
      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 class WFormWidget