Copy link to clipboard
Copied
Hopefully, I would get the help I seriously need this time around. I need help on the subject matter.
Can someone help me pls!!!!!!!!!!
Thanks.
Copy link to clipboard
Copied
Let me move this to the Acrobat forum for you, which is the appropriate forum for your question.
The Using the Community forum is for help in using the Adobe Support Community forums, not for help with specific programs. Product questions should be posted in the associated product community.
Copy link to clipboard
Copied
What want lock and unlock?
Copy link to clipboard
Copied
Thanks for responding. I would want the form user to access the form fields by the use of a password to access its content. This should be by the click of a button that would request a password.
Thanks
Copy link to clipboard
Copied
So you want to use the button to prompt the user for a password and if it's the correct one it should "unlock" all the other fields in the file, and when pressed again, it will "lock" them once more?
Copy link to clipboard
Copied
Exactly.
Copy link to clipboard
Copied
You can do it using this code:
var lockFields = event.target.buttonGetCaption()=="Lock";
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
if (event.target.name==fname) continue;
var f = this.getField(fname);
if (f==null) continue;
f.readonly = lockFields;
}
event.target.buttonSetCaption(lockFields ? "Unlock" : "Lock");
Copy link to clipboard
Copied
Sorry, forgot the password part... Will add now.
Copy link to clipboard
Copied
New version, this time with a password to unlock the fields (the correct password in this case is "12345"):
var lockFields = event.target.buttonGetCaption()=="Lock";
if (!lockFields) {
var resp = app.response("Enter the password to unlock the fields:","","");
if (resp!="12345") {
app.alert("Invalid password.");
lockFields = true;
}
}
for (var i=0; i<this.numFields; i++) {
var fname = this.getNthFieldName(i);
if (event.target.name==fname) continue;
var f = this.getField(fname);
if (f==null) continue;
f.readonly = lockFields;
}
event.target.buttonSetCaption(lockFields ? "Unlock" : "Lock");
Copy link to clipboard
Copied
I'm looking to do something similar. I would like the user to input the information into specific fields and be able to lock and unlock them the way that was described above. How can I change that script?
Copy link to clipboard
Copied
Change the middle part of the code above to this:
var fieldsToLock = ["Text1", "Text2", "Radio3", "CheckBox4"]; // replace with actual field names
for (var i=0; i<fieldsToLock.length; i++) {
var fname = fieldsToLock[i];
var f = this.getField(fname);
if (f==null) {console.println("ERROR: " + fname); continue;}
f.readonly = lockFields;
}
Copy link to clipboard
Copied
Thank you!
Copy link to clipboard
Copied
Okey. let me try it and get back to you.
Thanks.
Copy link to clipboard
Copied
I just noticed that also.
Copy link to clipboard
Copied
It worked like magic. thanks.
One more thing which is very important. i have a reset button which resets an invoice field i wouldn't want to reset except with a password. my form users click a check box to generate the invoice number serially. below is the script in that button.
var svfile = app.alert ("You are about to reset/delete all information on this form. Will you like to continue?", 2, 2);
if (svfile == 2 || svfile ==3) {
app.alert ("You may save a copy before reseting this form.", 1);
} else {
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f.type != "button")
{
f.readonly = false;
}
}
this.resetForm();
}
how do i include this lock and unlock script to this script with a different password i would only have access to.
Thanks.
Copy link to clipboard
Copied
Sorry, I don't quite follow... Could you share the file with us?
Copy link to clipboard
Copied
Attached is the form. the reset in at the bottom. each time they reset it, the invoiceID start counting from zero which is not appropriate. it results to a lot of clicks to get to the last used invoice number.
The point is that I should only have access to resetting the doc. number. we want the doc. number serially for audit reasons.
Thanks.
Copy link to clipboard
Copied
If you don't want the field's value to be affected you have two options:
- Change the defaultValue property of the field when you change the value property, so they are always the same.
- Instead of resetting the entire form create an array of all the field names, except for those you don't want to be changed, and pass that as a parameter to resetForm.
Copy link to clipboard
Copied
I guess there's another option:
- Save the field's value to a variable before resetting, then apply it back to it afterwards.
Copy link to clipboard
Copied
I understand for the second option which I already created on the form. but the first and third would work for me even though I don't fully understand it. i would want the form user not to skip a single number by double clicking and as a result asking me for a form reset.
Thanks.
Copy link to clipboard
Copied
You can do the third option I suggested like this:
var invoiceID = this.getField("InvoiceID1").valueAsString;
this.resetForm();
this.getField("InvoiceID1").value = invoiceID;
Copy link to clipboard
Copied
Okey.
Sorry I forgot to say that they are invoiceID1 and invoiceID2. How do I add invoiceID2 to the script.invoiceID2 is behind invoiceID1.
Thanks
Copy link to clipboard
Copied
Same thing:
var invoiceID1 = this.getField("InvoiceID1").valueAsString;
var invoiceID2 = this.getField("InvoiceID2").valueAsString;
this.resetForm();
this.getField("InvoiceID1").value = invoiceID1;
this.getField("InvoiceID2").value = invoiceID2;
Copy link to clipboard
Copied
That should be all for now. Thanks for your help. I really appreciate it.