Copy link to clipboard
Copied
Hi,
My aim is to lock a number of fields in a form with a password chosen by the person who will administrate the form. It is not a question of high security, it is only to make sure that the fields will not be modified by accidental clics or deletes.
I was able to accomplish what I wanted with the code suggested in this post : Re: Form Field Security .
I slightly modified the code for the password to be extracted from another field. Here it is :
--------------------------------------------------
(function () {
// Get one of the fields in the group
var f = getField("admin.logo");
// 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"
});
var pw=this.getField("Mot_passe").value;
switch (resp) {
case pw: // Your password goes here
getField("admin").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;
}
})();
----------------------------------------------
I applied this code as an action on a checkbox field, it works very well. Now, I also want the password field to hide if the fields have indeed locked, but to reappear when the fields unlock. So I created a following action with this code :
var a = this.getField("admin").readonly;
var b = this.getField("Mot_passe");
if (a = true) b.display=display.hidden;
else
b.display=display.visible;
It obeys perfectly to hiding the password field when my group of fields is locked, but will not return it to visible when the fields unlock.
Please, what do I need to change, if anyone can help? Thank you!
Use this:
var a = this.getField("admin.logo").readonly;
var b = this.getField("Mot_passe");
if (a) b.display=display.hidden;
else b.display=display.visible;
Copy link to clipboard
Copied
Use
if (a) ...
not
if (a=true) ...
Copy link to clipboard
Copied
Hi Bernd,
I have tried, and it made the password field reappear, but it no longer will hide. So I still have the same problem, but in reverse.
Copy link to clipboard
Copied
Use this:
var a = this.getField("admin.logo").readonly;
var b = this.getField("Mot_passe");
if (a) b.display=display.hidden;
else b.display=display.visible;
Copy link to clipboard
Copied
Works great, I'm baffled this morning because I really thought I had tried in this manner before. But it's working great now. Thanks!
Copy link to clipboard
Copied
this.getField("admin").readonly will always return false.
Copy link to clipboard
Copied
Thanks I'll keep it in mind.