Class WDateTimeEdit


public class WDateTimeEdit extends WLineEdit
A Date and Time field editor.

Wt/WDateTimeEdit.h

This editor is a line edit with support for a datetime entry. Users can fill in the datetime manually or rely on the popup. Using the icon of a calendar and clock.

In the popup a WTimePicker and WCalendar are shown to the user, allowing input in a more structured manner.

Note: The WTimePicker does not support timezones, and consequentially this widget doesn't either. If supplied, it is ignored.

See Also:
  • Constructor Details

  • Method Details

    • remove

      public void remove()
      Description copied from class: WFormWidget
      Destructor.
      Overrides:
      remove in class WFormWidget
      See Also:
    • setDateTime

      public void setDateTime(WDate dateTime)
      Sets the date and time.

      Does nothing if the dateTime is null.

      See Also:
    • getDateTime

      public WDate getDateTime()
      Returns the datetime.

      Reads the current datetime.

      Returns null if the datetime could not be parsed using the current getFormat().

      See Also:
    • getDateTimeValidator

      public WDateTimeValidator getDateTimeValidator()
      Returns the datetime validator.

      Most of the configuration of the date time edit is stored in the validator.

      See Also:
    • setNativeControl

      public void setNativeControl(boolean nativeControl)
      Configures whether a native HTML5 control should be used.

      When enabled, the browser's native datetime input (<input type="datetime-local">) will be used if available. This should provide a better experience on mobile browsers.

      Setting native control to true limits the format to "yyyy-MM-ddThh:mm".

      There is no support for changing the native control after the widget is rendered.

      By default, this is set to the value of WWebWidget.isDefaultNativeControl().

      See Also:
    • isNativeControl

      public boolean isNativeControl()
      Returns whether a native HTML5 control is used, if supported.

      Taking into account the preference for a native control, configured using setNativeControl(), this method returns whether a native control is actually being used.

      See Also:
    • setFormat

      public void setFormat(String format)
      Sets the format used for representing the datetime.

      This sets the format in the validator.

      The default format is based on the current WLocale.

      The format is set and limited to "yyyy-MM-ddThh:mm" when using the native HTML5 control. Changing to another format has no effect.

      Note: The WTimePicker does not support timezones, and consequentially this widget doesn't either. If supplied, it is removed.

      See Also:
    • getFormat

      public String getFormat()
      Returns the datetime format.

      See Also:
    • setBottom

      public void setBottom(WDate bottom)
      Sets the lower limit of the valid datetime range.

      This sets the lower limit of the valid datetime range in the datetime validator.

      See Also:
    • getBottom

      public WDate getBottom()
      Returns the lower limit of the valid datetime range.

      See Also:
    • setTop

      public void setTop(WDate top)
      Sets the upper limit of the valid datetime range.

      This sets the upper limit of the valid datetime range in the datetime validator.

      See Also:
    • getTop

      public WDate getTop()
      Returns the upper limit of the valid datetime range.

      See Also:
    • browseToPreviousYear

      public void browseToPreviousYear()
      Browses to the same month in the previous year.

      Displays the same month in the previous year. This does not affect the selection.

      This will not affect a native widget.

      See Also:
    • browseToPreviousMonth

      public void browseToPreviousMonth()
      Browses to the previous month.

      Displays the previous month. This does not affect the selection.

      This will not affect a native widget.

      See Also:
    • browseToNextYear

      public void browseToNextYear()
      Browses to the same month in the next year.

      Displays the same month in the next year. This does not change the current selection.

      This will not affect a native widget.

      See Also:
    • browseToNextMonth

      public void browseToNextMonth()
      Browses to the next month.

      Displays the next month. This does not affect the selection.

      This will not affect a native widget.

      See Also:
    • browseTo

      public void browseTo(WDate date)
      Browses to a date.

      Displays the month which contains the given date. This does not change the current selection.

      This will not affect a native widget.

      See Also:
    • getCurrentYear

      public int getCurrentYear()
      Returns the current year displayed.

      Returns the year that is currently displayed.

      This will not work on a native widget.

      See Also:
    • getCurrentMonth

      public int getCurrentMonth()
      Returns the current month displayed.

      Returns the month (1-12) that is currently displayed.

      This will not work on a native widget.

      See Also:
    • setHorizontalHeaderFormat

      public void setHorizontalHeaderFormat(CalendarHeaderFormat format)
      Sets the horizontal header format.

      The default horizontal header format is CalendarHeaderFormat.ShortDayNames

      This will have no effect on a native widget.

    • getHorizontalHeaderFormat

      public CalendarHeaderFormat getHorizontalHeaderFormat()
      Returns the horizontal header format.

      This will not work on a native widget.

    • setFirstDayOfWeek

      public void setFirstDayOfWeek(int dayOfWeek)
      Sets the first dat of the week.

      Possible values are 1 to 7. The default value is 1 ("Monday").

      This will have no effect on a native widget.

      See Also:
    • setHourStep

      public void setHourStep(int step)
      Sets the step size for the hours.

      This only impacts the time sections of the widget.

      This will have no effect on a native widget.

      See Also:
    • getHourStep

      public int getHourStep()
      Returns the step size for the hours.

      This will have no effect on a native widget.

      See Also:
    • setMinuteStep

      public void setMinuteStep(int step)
      Sets the step size for the minutes.

      This only impacts the time sections of the widget.

      This will have no effect on a native widget.

      See Also:
    • getMinuteStep

      public int getMinuteStep()
      Returns the step size for the minutes.

      This will have no effect on a native widget.

      See Also:
    • setSecondStep

      public void setSecondStep(int step)
      Sets the step size for the seconds.

      This only impacts the time sections of the widget.

      This will have no effect on a native widget.

      See Also:
    • getSecondStep

      public int getSecondStep()
      Returns the step size for the seconds.

      This will have no effect on a native widget. @see WDateTimeEdit#setSecondStep(int step)

      See Also:
    • setMillisecondStep

      public void setMillisecondStep(int step)
      Sets the step size for the milliseconds.

      This only impacts the time sections of the widget.

      This will have no effect on a native widget.

      See Also:
    • getMillisecondStep

      public int getMillisecondStep()
      Returns the step size for the milliseconds.

      This will have no effect on a native widget.

      See Also:
    • setWrapAroundEnabled

      public void setWrapAroundEnabled(boolean rollover)
      Enables or disables wraparound for the time.

      Wraparound is enabled by default. This will ensure that the widgets that selects the units of time will wrap around to their lowest possible value when exceeding their maximum value.

      This will have no effect on a native widget.

      See Also:
    • isWrapAroundEnabled

      public boolean isWrapAroundEnabled()
      Returns whether wraparound is enabled.

      This will have no effect on a native widget.

      See Also:
    • setHidden

      public void setHidden(boolean hidden, WAnimation animation)
      Description copied from class: WFormWidget
      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 WFormWidget
    • load

      public void load()
      Description copied from class: WWidget
      Loads content just before the widget is used.

      This function is called when a widget is inserted in the widget hierarchy. Widgets that get inserted in the widget hierarchy will be rendered. Visible widgets are rendered immediately, and invisible widgets in the back-ground (or not for a plain HTML session). This method is called when the widget is directly or indirectly inserted into the widget tree.

      The default implementation simply propagates the load signal to its children. You may want to override this method to delay loading of resource-intensive contents.

      During the life-time of a widget, this method may be called multiple times, so you should make sure that you do a deferred initialization only once.

      Overrides:
      load in class WInteractWidget
    • 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 WFormWidget
    • render

      protected void render(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 WLineEdit
    • setFromLineEdit

      protected void setFromLineEdit()
      Sets the value from the line edit to the calenbdar and time picker.
    • validatorChanged

      protected void validatorChanged()
      Overrides:
      validatorChanged in class WFormWidget
    • getType

      protected String getType()
      Overrides:
      getType in class WLineEdit