Announcement

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

    Event when form is saved

    I have a ListGrid and DynamicForm bound to the same data source. A nice feature of SmartClient is, is that when I save the form, the data in the grid gets updated as well. I was wondering in which event this happens because I want to add some logic of my own. I know there's a callback option for the submit() method of the form, but this doesn't get called when the form is submitted with the Enter-key (I have saveOnEnter set to true in the form).

    A little background:
    I also have editable ListGrids and I created a mechanism that after editing of a record, it gets reselected again (because it gets deselected by default after saving). Because my grid can't contain all editable fields, I have created a DynamicForm that handles the saving of data. After it saves, the grid row gets updated, but also deselected. I want to reselect it just like I do in editable grids (I use editComplete() in the grids).
    Last edited by wallytax; 29 Jul 2010, 00:55.

    #2
    I now tried this approach that seems to be working. Could anyone confirm whether this is a good approach:

    Code:
    isc.DynamicForm.create({
      ...,
      submit: function () {
        this.Super('submit', [function () {
          alert('It worked!');
        }]);
      }
    }

    Comment


      #3
      That's a reasonable approach, but make sure you pass the native "arguments" object to Super() as the third argument. It's required whenever you provide a new set of arguments.

      Also bear in mind, taking this approach, if ever were to pass a callback to saveData(), it would now be ignored since you're throwing away the callback argument to submit().

      Comment


        #4
        Regarding your first comment, do I need to remove the first argument from the arguments array before passing them on? (Because it's replaced by my callback).

        Regarding your second comment, I'm overriding submit() not saveData() or is the default submit() calling saveData() or something? I'm not sure what you mean, maybe an alternative approach and if so, do you any suggestions?

        I'm using this technique to create a universal DynamicForm that defines good defaults for the majority of the forms in my application.

        Comment


          #5
          Add the arguments like so:

          Code:
          isc.DynamicForm.create({
            ...,
            submit: function () {
              this.Super('submit', [function () {
                alert('It worked!');
              }], arguments);
            }
          }
          submit() is passed a callback. If you want upstream APIs like saveData() to continue to work, call that callback from your own, replacement callback.

          Comment


            #6
            Thanks for the reply, but this makes me wonder:
            1) Can't I make a general purpose wrapper method that only adds my logic and doesn't intervene with the default behavior?
            2) Would it be better to override saveData() instead of submit()
            3) Reading your response, makes me think I have to know the internals of SmartClient to make it safe to override this method.

            So I'm still in doubt whether this is the right approach then. I see the grid's data replaced when I save the form, so this is done in an callback method somewhere. After that callback I need to add my line of code.

            Comment


              #7
              1) Yes, but once again, you have to call the original callback that is passed into the method

              2) Doesn't matter

              3) No.

              Comment


                #8
                I've not run into serious problems with the matter described above, until today. I've searched the forum for a solution to a problem that's quite trivial I presume. I will first describe the situation I'm in and then the problem I want to solve. Any help is appreciated!

                - I'm using SmartClient 7.0rc2 (the JavaScript version)
                - I have a grid that doesn't display all fields an user might edit
                - Therefore I created a form that opens in a modal Window and shows all editable fields

                The problem: How to detect a successful form submittal? I want to close the modal window after the form is saved. I've tried the submittal trick described in earlier posts in this thread, but it's getting a bit messy and I'm very unsure if this is the way to go.

                To keep this as simple as possible: how would you implement a popup form that closes after it's data is saved successfully?

                Comment


                  #9
                  See post #5 in this thread. A callback is passed to submit() which is passed through. Replace this callback with your own function that you need called on completion, then use Class.fireCallback() to fire the original callback.

                  Comment


                    #10
                    Sorry, don't 100% exactly see what you mean. This is what I have:

                    Code:
                    isc.defineClass('GenericDynamicForm', isc.DynamicForm);
                    isc.GenericDynamicForm.addProperties({
                      ...
                      submit: function (callback, requestProperties) {
                        this.Super('submit', [function (response, data, requestProperties) {
                          if (callback) {
                            callback(response, data, requestProperties);
                          }
                        }, requestProperties]); 
                      },
                      ...
                    })

                    Comment


                      #11
                      This ought to do it:
                      Code:
                      isc.defineClass('GenericDynamicForm', isc.DynamicForm);
                      isc.GenericDynamicForm.addProperties({
                        ...
                        submit: function (callback, requestProperties) {
                          function customCallback (dsResponse, data, dsRequest) {
                            // XXX Custom code to execute before default callback, if desired.
                            doSomething();
                            if (callback) {
                              this.fireCallback(callback, "dsResponse,data,dsRequest", [dsResponse,data,dsRequest]);
                            }
                            // XXX Custom code to execute after default callback, if desired
                            doSomethingElse();
                          }
                      
                          this.Super('submit', [customCallback, requestProperties], arguments); 
                        },
                        ...
                      })

                      Comment


                        #12
                        That's neat, defining a function in another function, but clear enough. I will try this and let you know if this works.

                        Thanks anyway for this clear answer. I didn't took the time to reply to your post sooner, sorry for that... ;-)

                        Comment

                        Working...
                        X