3 Replies Latest reply: Jun 1, 2012 8:54 AM by NYY60504 RSS

    How to prevent duplicate submission?

    NoMan'sLand Community Member

      Hello!

       

      I have a page for gathering some data:

       

      private function saveHander():void {

          // Gathering data into database.

      }

       

      <mx:TextInput id="name" />

      <mx:TextInput id="age" />

      <s:Button id="Submit" label="Submit" click="saveHandler();" />

       

      When focus on submit button,I click at the button and press the space bar at the same time,saveHander function execute two times.

      How can I prevent duplicate submission? thanks!

        • 1. Re: How to prevent duplicate submission?
          na21han

          Hi

           

          you could put boolean in place to cancel second submit and unlock it again once request is returned

           

          private var pass:boolean = true;

          private function saveHander():void {

              // Gathering data into database.

                    if(pass == true)

                    {

                         pass = false;

                         //send request here

                    }

          }

          // fire this when data requested returns

          private function sendRequestReturn():void

          {

               pass = true;

          }

           

          <mx:TextInput id="name" />

          <mx:TextInput id="age" />

          <s:Button id="Submit" label="Submit" click="saveHandler();" />

          • 2. Re: How to prevent duplicate submission?
            NoMan'sLand Community Member

            Thanks for your reply.

            But has many the same questions in my application.Are there other easier methods?

            • 3. Re: How to prevent duplicate submission?
              NYY60504 Community Member

              Assuming this is a form you are attempting to save, good UX practice is to disable the form once you begin local form validation (submit button clicked) prior to forming your data packet for save.

              Doing so will prevent the anomaly you are experiencing.

               

              In other cases where the above practice is not practical, you can setFocus to another component (off the submit button) because as long as the focus remains on the button, depressing the space bar will trigger the mouse event for the button. Research ADA compliance if you want more details.

               

              HTH.