2 Replies Latest reply on Sep 10, 2012 6:55 AM by NativeShadow62

    lock admin fields

    NativeShadow62

      Used G. Johnson's code to lock - unlock multiple fields with a password.  Worked well...except it does not unlock the fields.  It hides the fields prior to the password...when password is put in...unhides the fields, but does not allow anything to be typed in. 

       

      Here is the code I used...I left all his documentation in and I would be willing to give anyone who helps credit for their help.

       

      (function() {

       

      // Get fields in the group

      var f=getField("Admin").readonly;

       

      //Determine new readonly state, which is the opposite of the current state

      var readonly=!f.readonly;

       

      var readonly_desc=readonly?"unlock":"lock";

       

      //Ask user for password

      var resp=app.response({

      cQuestion: "To"+readonly_desc+"thefields, enter the password:",

      cTitle: "Enter password",

      bPassword: true,

      cLabel: "Password"

      });

       

      switch (resp) {

       

      case "Admin_PassWord": //Your password goes here

      getField("Admin").readonly=readonly;

      getField("Admin").display=readonly.display?hidden:display.visible;

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

      break;

       

      case null://User pressed Cancel button

      break;

       

      default://Incorrect password

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

      break;

      }

      })();

       

       

      >>>>Any help would be appreciated.  I also need help with another issue.  I have been working on this form for several days and learned a lot that I didn't know.  I am enjoying the experience, but it is now beyond what I can figure out on my own....Info:

       

      I have a flight Log for a small company.  I have been able to figure out most of the need but 2...the one above and a second.  I am using Acrobat 9 and Javascript:

       

      1 I have a passenger manifest that need a count...I am having a problem with figuring out the code fo rthe counter itself, but the bigger problem is...the airplain may have up to 7 flights on 1 flight log, picking up and dropping off up to 9 passengers at any one flight.  I was thinking using a field that has to be filled by the pilots as a "trigger" (not sure of the term) to populate the counter field.  But the problem was that the number of passengers can changed from flight to flight.  Previous counts would change as the new flight started with the current number.

       

      2.  The above code.  I have 6 fields that the admin dept does not want the pilots to fill out, which they have been up to now.  The admin dept want these fields locked so that the pilots cannot access them.  They don't mind a password protection and I have been using G. Johnson's code thus far.  Like I said earlier...it works as far as the password is concerned and it shows the fields...but it does not unlock them.  Since the logs are not returned to the pilots there is no need to relock them but if necessary we can do that as well.

       

      Thus far I have figured out a lot of code for time calculations, counter for flights, and others, but after a week and a half I figure I need help.  Any would be highly appreciated.  Thank you for your time.  Since this is Friday...I hope everyone has a nice weekend and I will check this on Monday.

       

      NativeShadow

        • 1. Re: lock admin fields
          George_Johnson MVP & Adobe Community Professional

          There are a number of problems with the code. Here's a revised version. Compar it line by line so you understand the differences. The most important difference is with this line:

           

          var f = getField("Admin.Name");

           

          This is getting a field reference to a single field in the "Admin" group, not the entire group. So change "Admin.Name" to the name of an actual field that appears on your form.

           

           

          Here's the revised code:

           

          (function () {

           

              // Get fields in the group

              var f = getField("Admin.Name");

           

              //Determine new readonly state, which is the opposite of the current state

              var readonly = !f.readonly;

           

              var readonly_desc = readonly ? "lock" : "unlock";

           

              //Ask user for password

              var resp=app.response({

                  cQuestion: "To" + readonly_desc + "the fields, enter the password:",

                  cTitle: "Enter password",

                  bPassword: true,

                  cLabel: "Password"

              });

           

              switch (resp) {

           

              case "Admin_PassWord":  // Your password goes here

                  getField("Admin").readonly = readonly;

                  getField("Admin").display = readonly ? display.hidden : display.visible;

                  app.alert("The fields are now " + readonly_desc + "ed.", 3);

                  break;

           

              case null:  // User pressed Cancel button

                  break;

           

              default:  // Incorrect password

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

                  break;

              }

           

          })();

          • 2. Re: lock admin fields
            NativeShadow62 Level 1

            Ok.  I changed the code.  Unfortunately, the button no longer even opens up to enter the password.  I copied and pasted the code you had to the form.  Before when I clicked the password button it had a popup window asking for the password.  Now it doesn't even have that popup window.  Please help.