Announcement

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

    SubmitValuesHandler not called for setImplicitSaveOnBlur(true)

    For a simple DynamicForm with a TextItem and with:
    Code:
    setSaveOnEnter(true);
    setImplicitSaveOnBlur(true);
    the SubmitValuesHandler gets called on Enter key but not on blur. Is there something missing?

    Test case attached.

    SmartGWT: v12.1p_2020-06-19/LGPL Development Only (built 2020-06-19)
    Attached Files

    #2
    SubmitValues handler is for Enter keypresses, and parallels the HTML submit button. The implicitSave mechanism just calls saveData(), and does not do a submit.

    How is this affecting you? What is it you're trying to do?

    Comment


      #3
      I am just trying to do some custom actions and then add a Record to a data source (using the text from the TextItem) on enter or blur events on a text field. Enter action works just fine but not the blur one. I have updated the test case where even if I override the saveData() method of the form it is not entering there...
      Attached Files

      Comment


        #4
        See docs- saveData() is not marked as an override point. You can see of course that saving is attempted, so you can put code in lots of different places, such as DataSource.transformRequest(), to customize how saving is done.

        Comment


          #5
          I know I can customize the saving in transformRequest() but that is at model level and I need to make adjustments at UI level. More exactly after the user enters a value in the TextItem and presses Enter or leaves the TextItem, a record gets added to the DataSource using the entered data (I am able to do this) AND the form containing the TextItem gets removed from the UI and replaced with a Button or other component (this is the tricky part).

          I know I can add KeyPress and Blur handlers to the text field as a work around but I was hoping that there is a possibility to trigger the Submit action of the form (through saveOnEnter and saveOnBlur) and in the SubmitValuesHandler I can do my UI changes and then add my record to the DataSource... To me saveOnEnter and saveOnBlur sound like triggering the same behaviour...

          Comment


            #6
            saveOnEnter and saveOnBlur do indeed trigger the same behavior: they save. However, the concept of submitting is different and always has been - it's when the user actively submits the data. This concept comes from HTML, not us.

            However, now that you've told us what you're trying to do, the point is moot anyway, since even if submitValues fired on a blur, using that handler is the wrong approach: you should only be hiding your form after a successful save, otherwise, you could have validation errors and hide the form anyway.

            The simplest approach for your use case is probably just to watch for the dataChanged event on the target DataSource. If you're worried about saves from other components wrongly triggering the hiding of your form, you can check the componentId property on the DSRequest.

            Comment


              #7
              Make sure you check whether the response was successful (dsResponse.status), or, as previously mentioned, you could end up hiding your form when the save failed.

              Comment


                #8
                Originally posted by Isomorphic View Post
                However, now that you've told us what you're trying to do, the point is moot anyway, since even if submitValues fired on a blur, using that handler is the wrong approach: you should only be hiding your form after a successful save, otherwise, you could have validation errors and hide the form anyway.
                True for the general case and it is a point to keep in mind for the future. In my particular case it is just a string without validation...

                Originally posted by Isomorphic View Post
                The simplest approach for your use case is probably just to watch for the dataChanged event on the target DataSource. If you're worried about saves from other components wrongly triggering the hiding of your form, you can check the componentId property on the DSRequest.
                Briliant!!! I was using a boolean flag, set on true on action and on false on response to somehow simulate the source of the event :))) Obviously a bad simulation but did not know other solution... until now. I do not know how to thank you enough for this tip :)

                Comment


                  #9
                  Our pleasure, glad it's working for you.

                  Comment

                  Working...
                  X