Password-protect and hide one form field
blueskies_7 Sep 5, 2012 11:49 AMHi there,
I have been browsing through old forum discussions in search of an answer to my question. A code George Johnson posted was really helpful, but there's one more function I need to add to it and am struggling to figure it out on my own.
I am creating a PDF with form fields. Different depts within the organization will review this PDF and pass it back and forth. The Admin dept needs one text field called "internal comments" that they can password protect. They'd like to be able to add text, then password-protect that one field so it's hidden for other depts who review this PDF. Admin will need the copy to be visible to them when they enter their password.
The script I found works really well (see below). I set up a button to house the script, and when you click it, it locks and unlocks the "internal comments" text field with the password. However, I can't figure out how to HIDE the "internal comments" text field after someone in Admin inputs their information. I tried setting up a Show/Hide Field action, but I can't get it to work. And I'm just not savvy enough to know how to alter the Javascript.
How can I specify that the "internal comments" text field be HIDDEN when a user enters their password for "deactivate this field", and VISIBLE when they enter a password for "activate this field"?
Any help would be greatly appreciated!
---
(function () {
// Get one of the fields in the group
var f = getField("private.name");
// Determine new readonly state, which
// is the opposite of the current state
var readonly = !f.readonly;
var readonly_desc = readonly ? "deactivate" : "activate";
// 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 "your_password": // Your password goes here
getField("private").readonly = readonly;
app.alert("The fields are now " + readonly_desc + "d.", 3);
break;
case null : // User pressed Cancel button
break;
default : // Incorrect password
app.alert("Incorrect password.", 1);
break;
}
})();


