8 Replies Latest reply on Jul 21, 2014 7:07 PM by LunaKT

    Why are my radio buttons not renaming in pages spawned from a hidden template?

    LunaKT

      Hi Everyone,

       

      I am new to PDF forms, and have never before tried to use JavaScripts. However, I have been able to learn a lot and I have followed many threads and have almost accomplished what I want, but have hit a block. I don't understand the JavaScript well enough to locate my problem. Your help is greatly appreciated.

       

      SYSTEM SPECS: Adobe Acrobat X Pro  Mac OS 10.8.5

       

      WHAT I WANT: To create a multi-page (100 pages) form for grading student assignments. Each page must have the same fields, but as each page belongs to a new student, it needs to have different values in the fields on different pages. Each page has 4 questions to score, with 4 score possibilities for each question (0, 1, 2, 3 points), and so only one score should be able to be selected per question.

       

      WHAT I HAVE DONE, following the directions on this thread (Re: Multiple pages form) ):

       

      1) Created a form with a field for student name and 4 sets of radio buttons (Labeled Questions 1-4, with score choices 0-3).

      2) Placed a button at the bottom of the page that will spawn a new page and rename fields.

      3) Defined this page as a template.

      4) Spawned a page.

      5) Made the template "hidden."

       

      THE PROBLEM: Steps 1-4 above work perfectly--as long as the template (named "Form") is visible, when I click the button, a new page generates and the student name field renames the fields on Page 2 to "P2.Form.Student ID #" and the radio buttons rename to "P2.Form.Question 1" etc. Each time I press the button, it renames everything appropriately.

       

      However, if I hide the template, then when I click the button on page 1, the fields on Page 2 are renamed to "P1.Form.StudentID ##1." AND THE RADIO BUTTONS DO NOT RENAME. They get the name "P1.Form.Question 1" etc. So the student name field did rename in a way that allows me to enter a new name on each page, but it isn't actually reflecting that I am on page 2, and as for the radio buttons, at that point, I cannot enter different scores on different pages because they are all part of the same radio button grouping.

       

      If I use check boxes, they rename similarly to the student ID field, but I don't want to use check boxes because I want to return one possible score value for each question for tabulating the data. I don't want to leave the template visible because when I distribute this form to other graders, they may enter values into the template page without realizing it, and then when the spawn forms they will have wrong data already entered.

       

      Here is the script that I have set as the button's Mouse Up script:

       

      // Specify the name of the template
      var template_name = "Form";

       

      // Get a reference to the template
      var t = getTemplate(template_name);

       

      // Add a new page based on the template
      if (t !== null) {

       

          t.spawn({
          nPage: numPages,      // Add the new page to end of document
          bOverlay: false,      // Create a new page, not an overlay
          bRename: true         // Rename the fields
          });

       

      } else {
         app.alert("The template named \'" + template_name + " does not exist in this document.", 1);
      }

       

      Thanks for your help

        • 1. Re: Why are my radio buttons not renaming in pages spawned from a hidden template?
          gkaiseril MVP & Adobe Community Professional

          The code cannot be debugged without a sample form since the contents of the form is or is not modified by the code. You need to post a link to the sample form.

           

          It worked for me.

          • 2. Re: Why are my radio buttons not renaming in pages spawned from a hidden template?
            LunaKT Level 1

            Hi GKaiseril,

             

            Here is a link to the form that I am trying to build. Right now I have not hidden the template, so when you click the button it will spawn new pages, and as long as you don't fill out the first page, it works okay. But if you spawn a page, then hide the template, then try to spawn pages, it does not rename the radio buttons and they are all part of the same group. Thank you so much for your help.

            https://workspaces.acrobat.com/?d=RRRtLpv6VEBQPst17QsLCQ

            • 3. Re: Why are my radio buttons not renaming in pages spawned from a hidden template?
              gkaiseril MVP & Adobe Community Professional

              You need to spawn the template with a page number of 0. That is put the first page of the form before the template and then hide the template.

              • 4. Re: Why are my radio buttons not renaming in pages spawned from a hidden template?
                LunaKT Level 1

                Hi again GKaiseril,

                 

                If you have the time, would you be able to tell me how to do that? I tried just changing the page number of the template page to zero, but I get the error "Please enter a starting value of at least 1."  I definitely noticed that all of the discussions about similar subject do all say to somehow put the first page of the form before the template and then hide the template, but I don't think that I know how to do that. I read your response on this discussion "Re: Self replicating form pages in Acrobat Pro 9 (Win XP)" before I ever started this discussion, but have to admit that I can't figure out how to follow your advice "When I create a from that uses a template, I create the template and then spawn the 1st page of the form before the template and then work out the scripting for the 1st page and template and then hide the template."

                 

                Thanks

                • 5. Re: Why are my radio buttons not renaming in pages spawned from a hidden template?
                  LunaKT Level 1

                  Here is a link to a version of the form in which I spawned a new page by clicking on the button on the template page. Then using the Page Thumbnails pane, I dragged the new page (which spawned after the template page) to be before the template page. This is the only way that I know how to make the 1st page of the form be before the template, but obviously that is not the right way to do it. Then I hid the template. You can see that the form does not spawn properly. https://workspaces.acrobat.com/?d=eopMwv3Lc0WPFRK*6YXo5w

                  • 6. Re: Why are my radio buttons not renaming in pages spawned from a hidden template?
                    gkaiseril MVP & Adobe Community Professional

                    It is basically the script for spawning a page but one changes the page number to 0 and adds code to hide the template>

                     

                    // Specify the name of the template

                    var template_name = "Form";

                    // Get a reference to the template

                    var t = getTemplate(template_name);

                    // Add a new page based on the template

                    if (t !== null) {

                        t.spawn({

                        nPage: 0,      // Add the new page to start of document

                        bOverlay: false,      // Create a new page, not an overlay

                        bRename: true         // Rename the fields

                        });

                       t.hidden = true; // hide the template

                    } else {

                       app.alert("The template named \'" + template_name + " does not exist in this document.", 1, 0);

                    }

                     

                    If one does not hide the template and any of the fields on the template are filled in, then the template replicates the field with the value of the field.

                    • 7. Re: Why are my radio buttons not renaming in pages spawned from a hidden template?
                      LunaKT Level 1

                      Thank you so much for your time. I am so new to this, I'm not sure I am doing it correctly, I just (sort-of) figured out how to run JavaScripts in Acrobat at all, and I'm not sure of myself. Can I walk through for you what I am doing that I think is correct?

                      1. Start with a file that just has one page, and that page is designated as the template "Form."

                      2. Open the JavaScript Debugger

                      3. Paste the code that you gave above into the Console

                      4. It took me forever, but I finally figured out that I hold Shift and press Return in order to execute the script (on a Mac)

                       

                      At that point, it should spawn the page, correct? Instead, I get this message:

                       

                      SyntaxError: syntax error

                      1:Console:Exec

                      undefined

                      • 8. Re: Why are my radio buttons not renaming in pages spawned from a hidden template?
                        LunaKT Level 1

                        Well, I managed to do it by making a second button, putting your script as the action for the second button, then I pressed the button to generate the first page and hide the template. Then I unhid the template and deleted the button that I had used, then hid the template again. Not elegant in the slightest, but it accomplished what I was trying to do. Now the button acts appropriately when I press it, and things get renamed. Would still love to know how to do it correctly, but at least I got that somewhat done.

                         

                        HOWEVER...when I did a test Distribute of the form, then opened the "distributed" version of the PDF form...the button no longer generates a new page. I opened it in Acrobat X, same as what I had made it in. Is there some sort of setting that tried to make it Reader friendly that removed my spawn code?

                         

                        Thanks...again...it is neverending...