3 Replies Latest reply on Oct 31, 2011 11:21 AM by pguerett

    Custom Reset Button

    ew1220

      I want to create a reset button that clears the entire form except for 2 fields. Can this be done.

        • 1. Re: Custom Reset Button
          Steve L Walker Level 5

          As described by the doc you can use xfa.host.resetData() and pass a "A valid string listing either the names or the equivalent reference syntax expressions of the fields to reset. The list entries are delimited by the "," (comma) character. If the string is not present or empty, all the fields in the form are reset to their default value." For example, add a button of control type "regular" and add the following script to the click event:

           

          xfa.host.resetData("xfa.form.form1.TextField1,xfa.form.form1.TextField2");

           

          It is possible to reset fields by subform by finding all of the nodes that have the className "field".

           

          // form1.page1.subform1.resetBtn::click - (JavaScript, client)

           

          var fieldNames = '"';

           

          for (var i=0; i < subform1.nodes.length; i++) {

                    if (subform1.nodes.item(i).className == "field") {

             var fieldStr = "subform1." + subform1.nodes.item(i).name + '"';

             fieldNames = fieldNames + fieldStr;

                    }

          }

           

          fieldNames = fieldNames.substring(0,fieldNames.length - 1) + "'";

          xfa.host.resetData(fieldNames);

           

          Steve

          1 person found this helpful
          • 2. Re: Custom Reset Button
            ew1220 Level 1

            From your example I figured this out. Works great. However, not quite what I am looking for. Example: I have a form with 100 fields. I want to be able to clear (reset) 98 of them, while leaving the other 2 untouched. Can we modify this script, xfa.host.resetData() to exclude the 2 fields, rather than modifing it to include the other 98? What I am looking at here is the time factor in creating the custom button.

            • 3. Re: Custom Reset Button
              pguerett Level 6

              The reset button is either reset the enter form or just the fields you pass to it. So you might find it easier to save the value of the 2 fields, reset the form then set the 2 fields back to what they were.

               

              Or if you wrap the fields you want in a subform , you can rest the subform and all child nodes of the subform woudl be reset as well. If you decide to go this route the make sure that the binding for the wrapping subform is set to none.

               

              Paul