Announcement

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

    12.0p: Access to FormItem oldValue in ChangedHandler?

    Hi Isomorphic,

    is there a built in way of getting the oldValue in a ChangedHandler of a FormItem? Or do I have to somehow store it myself in an overridden setValue()?
    Use case:
    Appointments with start and end. On move of start, I want to move end by the same amount start was moved (like it is happening in Outlook and google calendar).
    Therefore I need to compute the difference between oldStart and newStart.

    event.getValue() says in the docs:
    The current value (after the change).
    Thank you & Best regards
    Blama

    #2
    The oldValue is available in the ChangeHandler, use that instead of the ChangedHandler. The difference is that the ChangeHandler fires before the change has happened, and the ChangedHandler after.

    Comment


      #3
      Hi Isomorphic,

      OK, but if I remember correctly, ChangeHandler fires way more often (e.g. for every keypress when entering a fate) and not only when the new value is accepted after tabbing out.
      IMHO I'd need some way to access the old stored value inside a ChangedHandler.

      Best regards
      Blama

      Comment


        #4
        Then you would store it from the ChangeHandler.

        Comment


          #5
          Hi Isomorphic,

          but what happens if the value is rejected somehow after tabbing out? Then I've overwritten the old value with a value that is not stored in the end.

          Best regards
          Blama

          Comment


            #6
            If you write a ChangeHandler that rejects the value, then you are correct, you would not want to store that value.

            It's not clear what other scenario you're talking about, where a value is rejected.

            Comment


              #7
              Hi Isomorphic,

              the value might not be "complete", as we are talking about DateItems here, where not every keypress makes the result a date.
              Also, normally you'd want such changes only after exit, like in the described use case.

              To make it easier, imagine a tool to resize images with an checked "keep aspect ratio" checkbox:
              Code:
              DynamicForm:
              FormItem(Integer) 1: Image current width: 20
              FormItem(Integer) 2: Image current height: 20
              FormItem(Boolean) 3: Keep aspect ratio: checked
              
              I want to make the image 10x10. My steps:
              Click into width.
              Click END key
              Click Backspace key (change called)
              Click Backspace key (change called)
              Enter 1 (change called)
              Enter 0 (change called)
              Hit Tab (change[B]d[/B] called)
              Inside widthFormItem-changedHandler: calculate oldWidth/height * newWidth -> heightFormItem.setValue(calculatedValue)
              
              One would [B]not[/B] want changes to heightFormItem for every change-call, only after entering the new width is finished.
              Best regards
              Blama

              Comment


                #8
                keyPress doesn’t trigger change for DateItem for that very reason.

                Our suggestions already seem to address the use case described very well. In fact in that case the old value isn’t even needed, so we’re at a loss trying to understand how you still need something else.

                Comment


                  #9
                  Hi Isomorphic,

                  OK, I'll give it a try for DateItem.
                  But in the "keep aspect ratio"-case you do need oldWidth, height, newWidth in the changedHandler, see the formula. Or am I missing something very obvious here?

                  Best regards
                  Blama

                  Comment


                    #10
                    There are other ways to do it that wouldn’t require the old sizes, however, at the risk of repeating ourselves, we’ve already provided a simple way to get the oldValue.

                    Comment

                    Working...
                    X