Announcement

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

    Form double submission detection via SubmitValuesHandler & ClickHandler

    I have a DynamicForm which has 2 event handlers that allow the form to be submitted: Button->ClickHandler and Dynamicform->SubmitValuesHandler with setSaveOnEnter(true).

    This of course results in the form being submitted twice if the user tabs to the Submit button to be in focus and presses Enter. This fires both events. I tried various things to try to keep track of the submissionInProgress but nothing seems to help to cancel either of the events.

    Is there an easy way to prevent this? I would really like to allow the users to use both Enter as well being able to click on the Submit button.

    I am using SmartGWT 3.1.

    Thanks,
    Henry

    #2
    Thanks for pointing this out - we'll make a framework change to avoid this, but in the meantime, you should be able to avoid the double submit by using targetIsMasked to determine that the form is masked (because this happens while saving).

    Comment


      #3
      Thanks for a quick response and suggestion. I can't seem to find any examples that would use targetIsMasked(), if possible, can you please post a quick example?

      thanks.

      Comment


        #4
        ? It's a static method, so EventHandler.targetIsMasked(form).

        Comment


          #5
          That was the first thing I tried but it didn't work for me. Perhaps I am missing something else. I have a plain DynamicForm that has a Button (not ButtonItem) added as child, here is the code that triggers submission.

          Code:
                  final DynamicForm userSearchForm = new DynamicForm();
                  userSearchForm.setSaveOnEnter(true);
          
                  final Button userSearchButton = new Button("Search");
                  userSearchButton.addClickHandler(new ClickHandler() {
                      @Override
                      public void onClick(ClickEvent clickEvent) {
                          if(!EventHandler.targetIsMasked(userSearchForm))
                              submitUserSearch(userIDItem);
                      }
                  });
          
                  userSearchForm.addSubmitValuesHandler(new SubmitValuesHandler() {
                      @Override
                      public void onSubmitValues(SubmitValuesEvent submitValuesEvent) {
                          if(!EventHandler.targetIsMasked(userSearchForm))
                              submitUserSearch(userIDItem);
                      }
                  });

          Comment


            #6
            We don't know what submitUserSearch() does, but the targetIsMasked() check should work if you are doing a save operation via a DataSource (where you have not customized showPrompt to disable masking).

            If you're doing some other kind of save, targetIsMasked() won't help and you just need to detect the double submit yourself.

            Comment


              #7
              that must be it then. I am not using datasource save, it's a direct RPC call.

              thanks for your help. If I find a programmatic way of trapping double-submit, I'll post it here.

              Comment


                #8
                Found a work-around if anyone ever stumbles on this.

                Adding Enter key in the button click event handler did the trick:

                Code:
                userSearchButton.addClickHandler(new ClickHandler() {
                            @Override
                            public void onClick(ClickEvent clickEvent) {
                                if (EventHandler.getKey() != null && EventHandler.getKey().equalsIgnoreCase("Enter")){
                                    clickEvent.cancel();
                                }
                                submitUserSearch(userSearchForm, userIDItem);
                //                System.err.println("Processing button click");
                            }
                        });

                Comment

                Working...
                X