8 Replies Latest reply on Nov 29, 2012 5:16 AM by ahlaj77

    Lock Text Fields Only If They are Filled Out

    ahlaj77 Level 1

      Hello to all and thank you in advance for your help!

       

      My Question:

      When I click a button (btnLockFields), I would like to lock only the text fields that have actual text in them filled out. The same text fields will not be filled out everytime, so it needs to be flexible. Before locking text fields, I need to be prompted to enter a password. I will be sending this form out to others so I need the password on the button to keep it secured from other users.

       

      I will put security on the form so others with Adobe Acrobat can't mess with the form.

       

      Is this possible to do? Thanks again!

       

      I've already seen this post but it works for specific fields unless there is a way to fix the code to work with what I am needing:

      http://forums.adobe.com/message/4695376

        • 1. Re: Lock Text Fields Only If They are Filled Out
          George_Johnson MVP & Adobe Community Professional

          To keep that script simple, I took advantage of hierarchical field names to affect all of the ones with the same prefix with a single statement. You could add a loop to go through the fields and don't set any fields that are empty to read-only. Are you asking for help modifying the script?

          • 2. Re: Lock Text Fields Only If They are Filled Out
            ahlaj77 Level 1

            Hi George thanks for the reply!

             

            I like the idea of putting the prefix before the field name. I actually put the code in a practice PDF form to test and see how it works.

            Would you be able to help me modify the script where it loops through all the fields (i can put prefixes infront of the field names) to allow the field names that are filled out to become readonly and field names that are empty stay unlocked? Also, I would like to keep the password ability you have in that script.

             

            Thanks!

            • 3. Re: Lock Text Fields Only If They are Filled Out
              George_Johnson MVP & Adobe Community Professional

              So do you want to loop through all of the fields (including buttons) that are present, or just those that have a particilar prefix?

              • 4. Re: Lock Text Fields Only If They are Filled Out
                ahlaj77 Level 1

                My form consists of both checkboxes and textfields. If I can loop without adding a prefix that would save me time (I have 6 pages in my PDF document) but if adding a prefix would be better I can do that as well.

                 

                Thanks!

                • 5. Re: Lock Text Fields Only If They are Filled Out
                  George_Johnson MVP & Adobe Community Professional

                  OK, you could try something like the following, but I haven't tested it. It is intended to be used in a bookmark and does not attempt to unlock after they've been locked:

                   

                  // Lock all of the non-empty fields

                  (function () {

                     

                      // Your chosen password goes here

                      var pw = "1234";

                   

                      //Prompt user for the password

                       var resp = app.response({

                          cQuestion: "To lock the non-empty fields, enter the password:",

                          cTitle: "Enter password",

                          bPassword: true,

                          cLabel: "Password"

                      });

                   

                      switch (resp) {

                      case pw:

                          // Loop through the fields and lock checked check boxes and non-blank text fields

                          for (var i = 0; i < numFields; i++) {

                   

                              var fName = getNthFieldName(i);

                              var f = getField(fName);

                   

                              if (f.type === "checkbox" && f.value !== "Off") {

                                  f.readonly = true;

                              }

                              if (f.type === "text" && f.valueAsString) {

                                  f.readonly = true;

                              }

                          }

                          app.alert("The fields are now locked.", 3);

                          break;

                      case null:  // User pressed Cancel button

                          break;

                      default:  // Incorrect password

                          app.alert("Incorrect password.", 1);

                          break;

                      }

                   

                  })();

                  • 6. Re: Lock Text Fields Only If They are Filled Out
                    ahlaj77 Level 1

                    Hi George,

                     

                    Instead of using a button I will try it in a bookmark. I'll let you know once I test it!

                     

                    Thank you VERY much for your help so far!

                    • 7. Re: Lock Text Fields Only If They are Filled Out
                      George_Johnson MVP & Adobe Community Professional

                      The latest script will work fine in a button since it's set up to just affect text fields and check boxes.

                      • 8. Re: Lock Text Fields Only If They are Filled Out
                        ahlaj77 Level 1

                        Hi George,

                         

                        Would there be a way to possibly make this current script have the ability to unlock as well (like your previous script in the other forum post)? Your current script you provided works great and I will use it! You are the ultimate Adobe helper!

                         

                        Thank you!