Class WFormWidget

Direct Known Subclasses:
WAbstractToggleButton, WComboBox, WLineEdit, WPushButton, WSlider, WTextArea

public abstract class WFormWidget
extends WInteractWidget
An abstract widget that corresponds to an HTML form element.

A WFormWidget may receive focus (see isCanReceiveFocus()), can be disabled, and can have a label that acts as proxy for getting focus. It provides signals which reflect changes to its value, or changes to its focus.

Form widgets also have built-in support for validation, using setValidator(). If the validator provide client-side validation, then an invalid validation state is reflected using the style class "Wt-invalid". All validators provided by JWt implement client-side validation.

On the server-side, use validate() method to validate the content using a validator previously set.

  • Constructor Details

  • Method Details

    • remove

      public void remove()
      Destructor.

      If a label was associated with the widget, its buddy is reset to null.

      Overrides:
      remove in class WInteractWidget
      See Also:
      WContainerWidget.removeWidget(WWidget widget)
    • getLabel

      public WLabel getLabel()
      Returns the label associated with this widget.

      Returns the label (if there is one) that acts as a proxy for this widget.

      See Also:
      WLabel.setBuddy(WFormWidget buddy)
    • setHidden

      public void setHidden​(boolean hidden, WAnimation animation)
      Sets the hidden state of this widget.

      If the widget has a label, it is hidden and shown together with this widget.

      Overrides:
      setHidden in class WWebWidget
    • getValueText

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

      This returns the current value as a string.

    • setValueText

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

      This sets the current value from a string value.

    • setValidator

      public void setValidator​(WValidator validator)
      Sets a validator for this field.

      The validator is used to validate the current input.

      If the validator has no parent yet, then ownership is transferred to the form field, and thus the validator will be deleted together with the form field.

      The default value is null.

      See Also:
      validate()
    • getValidator

      public WValidator getValidator()
      Returns the validator.
    • validate

      public WValidator.State validate()
      Validates the field.

      See Also:
      validated()
    • setEnabled

      public void setEnabled​(boolean enabled)
      Sets whether the widget is enabled.

      A widget that is disabled cannot receive focus or user interaction.

      This is the opposite of WWebWidget#setDisabled().

    • setReadOnly

      public void setReadOnly​(boolean readOnly)
      Sets the element read-only.

      A read-only form element cannot be edited, but the contents can still be selected.

      By default, a form element area is not read-only.

      See Also:
      setEnabled(boolean enabled)
    • isReadOnly

      public boolean isReadOnly()
      Returns whether the form element is read-only.

      See Also:
      setReadOnly(boolean readOnly)
    • setEmptyText

      public void setEmptyText​(java.lang.CharSequence emptyText)
      Deprecated.
      Sets the placeholder text (deprecated).

    • getEmptyText

      public WString getEmptyText()
      Deprecated.
      Returns the placeholder text (deprecated).

    • setPlaceholderText

      public void setPlaceholderText​(java.lang.CharSequence placeholderText)
      Sets the placeholder text.

      This sets the text that is shown when the field is empty.

    • getPlaceholderText

      public WString getPlaceholderText()
      Returns the placeholder text.

      See Also:
      setPlaceholderText(CharSequence placeholderText)
    • changed

      public EventSignal changed()
      Signal emitted when the value was changed.

      For a keyboard input, the signal is only emitted when the focus is lost

    • selected

      public EventSignal selected()
      Signal emitted when ??
    • validated

      public Signal1<WValidator.Result> validated()
      Signal emitted when the widget is being validated.

      This signal may be useful to react to a changed validation state.

      See Also:
      validate()
    • refresh

      public void refresh()
      Description copied from class: WWidget
      Refresh the widget.

      The refresh method is invoked when the locale is changed using WApplication#setLocale() or when the user hit the refresh button.

      The widget must actualize its contents in response.

      Note: This does *not* rerender the widget! Calling refresh() usually does not have any effect (unless you've reimplemented refresh() to attach to it an effect).

      Overrides:
      refresh in class WWebWidget
    • setToolTip

      public void setToolTip​(java.lang.CharSequence text, TextFormat textFormat)
      Description copied from class: WWidget
      Sets a tooltip.

      The tooltip is displayed when the cursor hovers over the widget.

      When textFormat is XHTMLText, the tooltip may contain any valid XHTML snippet. The tooltip will then be rendered using JavaScript.

      Note: This will set deferred tooltip to false.

      Overrides:
      setToolTip in class WWebWidget
    • isCanReceiveFocus

      public boolean isCanReceiveFocus()
      Description copied from class: WWidget
      Returns whether the widget can receive focus.

      Overrides:
      isCanReceiveFocus in class WWebWidget
      See Also:
      WWidget.setCanReceiveFocus(boolean enabled)
    • getTabIndex

      public int getTabIndex()
      Description copied from class: WWidget
      Returns the tab index.

      Overrides:
      getTabIndex in class WWebWidget
      See Also:
      WWidget.setTabIndex(int index)
    • enableAjax

      protected void enableAjax()
      Description copied from class: WWidget
      Progresses to an Ajax-enabled widget.

      This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.

      You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.

      Overrides:
      enableAjax in class WWebWidget
      See Also:
      WApplication.enableAjax()
    • 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 WWebWidget
    • propagateSetEnabled

      protected void propagateSetEnabled​(boolean enabled)
      Description copied from class: WWidget
      Propagates that a widget was enabled or disabled through children.

      When enabling or disabling a widget, you usually also want to disable contained children. This method is called by setDisabled() to propagate its state to all children.

      You may want to reimplement this method if they wish to render differently when a widget is disabled. The default implementation will propagate the signal to all children.

      Overrides:
      propagateSetEnabled in class WInteractWidget