Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Display only "time" of DateTimeItem

    Hello Everyone,

    I use a DateTimeItem to hold Date and Time information. But the user should only be able to change the time.

    The Date Part is filled in by using the ".setEditorValueParser" and contains a fixed date (Provided by the program).*Edit
    The Time Part should be entered by the user.

    The Textfield of the DateTimeItem contains "<date> <time>" like "04.07.2017 18:14".
    What i am trying, is to change the displayed text to "<time>" like "18:14".

    I was able to change the Displayed Output like this:
    Code:
            this.setEditorValueFormatter((value, record, form, item) -> {
                Date date;
    
                if (value instanceof String) {
                    date = LocalDateTimeConverter.localDateTimeStringToDate((String) value);
                } else {
                    date = (Date) value;
                }
                return LocalTimeType.LOCAL_TIME_FORMAT.format(date);
              }
    But of cause this changes the Value of the DateTimeItem, too.
    Is there a Way to change only the displayed text of the DateTimeItem?
    Last edited by JayG; 13 Jul 2017, 23:01.

    #2
    Is there some reason you would start down this path instead of just using TimeItem?

    Comment


      #3
      Well, a TimeItem cant hold a specific Date, can it?
      May it became unclear, when i tryed to break down the problem. My apologies.

      I extendet the DateTimeItem and try to implement two new Funktions (See below). So there is a posibility to set a fixed Time or a fixed Date to the Form-Element, on the Client-Side. The user sould only be able to see and edit the the part of the Element, that is not fixed. Hope this is more understandable. Thank you in advance!

      Code:
      public void fixDate(Date fixedDate) {...}
      and
      Code:
      public void fixTime(Date fixedTime) {...}
      Edit:
      Well.. i found a solution.
      I used "DateTimeItem.setEditorValueParser(...)" to manipulate the Data send to Server. Which means i add the Fixed Value.
      And i used "DateTimeItem.setEditorValueFormatter(...)" to parse the Value, that will be displayed inside the Textfild of the Formular.

      Anyway. Thanks for your time!
      Last edited by JayG; 14 Jul 2017, 01:50.

      Comment


        #4
        Your best bet is probably to extend CanvasItem instead of DateTimeItem:

        - setShouldSaveValue(true)
        - add a ShowValue handler that expects to receive a Date instance (a datetime) - use DateUtil.getLogicalDate/TimeOnly() to split the incoming date - store the logicalDate locally (say, as staticDate), call (see below) timeItem.setValue() with the logical time
        - setCanvas() with a DynamicForm containing a timeItem - the timeItem should have a Changed handler which combines timeItem.getValue() and staticDate, via a call to DateUtil.combineLogicalDateAndTime()
        Last edited by Isomorphic; 14 Jul 2017, 02:31.

        Comment

        Working...
        X