4 Replies Latest reply on Sep 20, 2012 2:47 AM by BrianJ011980

    Reset form fields

    J2ee_user
      Hi,

      I have a situation where I input data, submit the form and I return back to the same form. But when I return back, I want all the fields to be reset (say textbox to spaces etc similar to simple html reset).

      How do I do it?

      Thanks.
        • 1. Re: Reset form fields
          jfillman Level 1
          You'll have to set each from item's text value to an empty string.

          private function clearForm():void{
          myField1.text = '';
          myField2.text = '';
          }

          You may also want to disable the history manager, otherwise a user hitting the back/forward browser buttons could cause trouble for you.
          • 2. Re: Reset form fields
            J2ee_user Level 1
            I need to reset my form fields whenever I display that screen (its an input screen). So I've to do it at form load.

            In this case, in which event should I call this function?
            • 3. Re: Reset form fields
              jfillman Level 1
              I would do this in one of two places, possibly both.

              I would do this when the form is submitted, although you need to be sure to capture any validation and submission errors before clearing the fields. You don't want to clear the form before everything is submitted successfully.

              The second way is at the state change:

              private function stateChange():void{
              myField1.text = '';
              myField2.text = '';
              currentState = 'myState;
              }

              That way, anytime that state is displayed, all the fields on that state are cleared out.
              • 4. Re: Reset form fields
                BrianJ011980

                Thanks, this helped a lot.