Announcement

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

    Date and Time form items - invalid saveOnEnter handling

    It seems that the date and time related form items don't handle saveOnEnter properly. The value returned by getValue while executing submit handler is outdated.

    Here's the minimal code, tested on the Smart Client showcase: https://www.smartclient.com/smartcli...e/?id=timeItem

    Code:
    isc.DynamicForm.create({
        saveOnEnter: true,
        submit: function () {
            var time = this.getItem("textTime").getValue();
            isc.say("Time: " + time);
        },
        fields: [
            {name: "textTime", title: "Time", type: "time"}
        ]
    });
    To reproduce:
    1. Type in time (e.g. 12:00)
    2. Hit enter -> "Time: null"
    3. Close dialog window
    3. Hit enter -> "Time: Thu Jan 01 1970 12:00:00 GMT+0100"

    Value returned in step 2 and 4 should be the same. It works when between 1 and 2 I leave text field, making it lose focus.
    Last edited by Crack; 25 Jan 2018, 03:29.

    #2
    See the doc for FormItem.changeOnKeypress - if that's false, as it is by default for TimeItems, getValue() will return the old value until the item loses focus.

    You can just do something like this before calling getValue():

    Code:
        if (item.isFocused()) item.blur();

    Comment


      #3
      Ok, I will do it this way.

      But shouldn't new values be accepted when form is being submitted? I.e. I treat form submission as implicit blur - I finished with filling, press ENTER to save, and expect that at this moment all values are applied and valdiated.

      BTW, item in form doesn't have "blur" method and "isFocused" returns "undefined" instead of valid boolean (run example, write eg: "12:00" in field and press enter):
      Code:
      isc.DynamicForm.create({
          saveOnEnter: true,
          submit: function () {
              var item = this.getItem("textTime");
              isc.say("focused? " + item.isFocused() + "<br>" + "has blur()? " + (item.blur !== undefined));
          },
          fields: [
              {name: "textTime", title: "Time", type: "time"}
          ]
      });
      Result:
      focused? undefined
      has blur()? false
      Recalculating works by calling "item.blurItem()" or "this.blur()"

      Comment


        #4
        Yes, you're right - the focus-item should update it's value before submit(), and this was true for most item-types - we've fixed it for Date/Time-based items for builds dated January 28 and later.

        Comment


          #5
          Thanks. Now it works for date inputs, but looks like DateTime got/is broken when I change time (works when I change time and date).

          Run this code:
          Code:
          isc.DynamicForm.create({
              saveOnEnter: true,
              submit: function () {
                  var time = this.getItem("textTime").getValue();
                  isc.say("Time: " + time);
              },
              fields: [
                  {name: "textTime", title: "Time", type: "datetime"}
              ]
          });
          Broken DateTime input, test 1:
          1. Choose any date (eg. "02/06/2018 11:36"), click Apply
          2. Press ENTER: "Time: Tue Feb 06 2018 11:36:00 GMT+0100" - ok
          3. Change hour to 12:37 by using text input.
          4. Press ENTER: "Time: Tue Feb 06 2018 11:36:00 GMT+0100" - wrong

          Broken DateTime input, test 2:
          1. Choose any date (eg. "02/06/2018 11:36"), click Apply
          2. Press ENTER: "Time: Tue Feb 06 2018 11:36:00 GMT+0100" - ok
          3. Change only hour to 12:37 by using picker.
          4. Press ENTER: "Time: Tue Feb 06 2018 11:36:00 GMT+0100" - wrong

          Comment


            #6
            This has also been fixed, for builds dated January 7 and later.

            Comment

            Working...
            X