5 Replies Latest reply on Oct 17, 2013 5:50 PM by George_Johnson

    Button To Delete Multiple Buttons?

    itzrandy

      Greetings all.  I have a form which has a hidden button to spawn multiple pages based upon the initial page.  With help from MVP George Johnson, he showed me how to create a user prompt to ask how many pages the user needs to spawn.  Since most of the time, that will be 200 pages, I now have 200 buttons sitting out there.  Since this form is going to be placed into the wild, I need a way to delete those spawn buttons once the multi-page document has been created.  Basically, I'll just quickly create a button that will delete all 200 of the spawn buttons.  The problem is, each button has a unique field name based upon the page it was placed on (e.g. "P1.Temp1.Button1").  How do I write code that will ignore the page number ("P1"), per se and focus on the "Temp1.Button1" or even just "Button1", so that all the buttons are selected for deletion?

       

      Apologies if this is a rookie question, but let's face it, I just revealed my rookie status!  Any help out there?

       

      Thanks,

       

      Randy

        • 1. Re: Button To Delete Multiple Buttons?
          George_Johnson MVP & Adobe Community Professional

          All you need to do is delete the button just after you spawn the template. For example:

           

          // Spawn the specified number of pages

          for (var i = 0; i < num; i += 1) {

              if (i === 0) {

                  var oXO = t.spawn({nPage: numPages, bRename: true, bOverlay: false});

              } else {

                  t.spawn({nPage: numPages, bRename: true, bOverlay: false, oXObject: oXO});

              }

           

              // Delete the button

              removeField("P" + (numPages - 1) + ".Temp1.Button1");

          }

          • 2. Re: Button To Delete Multiple Buttons?
            itzrandy Level 1

            George,

             

            Clearly I am doing something wrong.  I tried plugging in the code from "// Delete the button" to the end, with no luck.  Here's the current code that you gave me for spawning the pages.  Where or how do I plug in the removeField action?

             

            Current functioning code:

             

            var resp = app.response({

             

             

                cQuestion: "How many pages to you want to add?",

             

             

                cTitle: "Enter number of pages to add",

             

             

                cDefault: "1",

             

             

                cLabel: "Pages:"

             

             

            });

             

             

             

             

             

            // Get a reference to the template to spawn

             

             

            var t = getTemplate("temp1");

             

             

             

             

             

            // Only proceed if user enteres a value,

             

             

            // that can be converted to a number,

             

             

            // and the number is at least 1 and no more than 200

             

             

            if (resp && !isNaN(+resp) && +resp >= 1 && +resp <= 200) {

             

             

             

             

             

                // Round number of pages to nearest integer

             

             

                var num = Math.round(+resp);

             

             

             

             

             

                // Spawn the spacified number of pages

             

             

                for (var i = 0; i < num; i += 1) {

             

             

                    if (i === 0) {

             

             

                        var oXO = t.spawn({nPage: numPages, bRename: true, bOverlay: false});

             

             

                    } else {

             

             

                        t.spawn({nPage: numPages, bRename: true, bOverlay: false, oXObject: oXO});

             

             

                    }

             

             

                }

             

             

             

             

             

            } else {

             

             

                app.alert("You entered an invalid number: " + resp);

             

             

            }

            • 3. Re: Button To Delete Multiple Buttons?
              George_Johnson MVP & Adobe Community Professional

              Place it just after the code I showed it coming after. I posted a fragment of the script you just posted, it wasn't meant to be the entire script.

              • 4. Re: Button To Delete Multiple Buttons?
                itzrandy Level 1

                Thank you once again, George.  I finally figured out why it wasn't working for me.  The code for the field name is case sensitive and I used "T"emp1 instead of "t"emp1 for the template name!  All is now good in button world!

                 

                I sincerely appreciate your assistance!

                 

                Randy

                • 5. Re: Button To Delete Multiple Buttons?
                  George_Johnson MVP & Adobe Community Professional

                  Great, it's good to know it's working.