Skip to main content
Eli-zabelle
Inspiring
August 3, 2017
Answered

Lock fields with password

  • August 3, 2017
  • 1 reply
  • 2969 views

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!

This topic has been closed for replies.
Correct answer Bernd Alheit

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;

1 reply

Bernd Alheit
Community Expert
Community Expert
August 3, 2017

Use

if (a) ...

not

if (a=true) ...

Eli-zabelle
Inspiring
August 3, 2017

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.

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
August 4, 2017

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;