• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Lock fields with password

Explorer ,
Aug 03, 2017 Aug 03, 2017

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!

TOPICS
Acrobat SDK and JavaScript

Views

2.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 04, 2017 Aug 04, 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;

Votes

Translate

Translate
Community Expert ,
Aug 03, 2017 Aug 03, 2017

Copy link to clipboard

Copied

Use

if (a) ...

not

if (a=true) ...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 03, 2017 Aug 03, 2017

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2017 Aug 04, 2017

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;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2017 Aug 04, 2017

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2017 Aug 04, 2017

Copy link to clipboard

Copied

this.getField("admin").readonly will always return false.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 05, 2017 Aug 05, 2017

Copy link to clipboard

Copied

LATEST

Thanks I'll keep it in mind.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines