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

Form field lock/unlock with password

Participant ,
Jun 25, 2018 Jun 25, 2018

Copy link to clipboard

Copied

I am using below code in bookmark to lock group of fields in my acroform. I found this code in https://forums.adobe.com/message/8679934#8679934 made by  George_Johnson. I used two bookmark for two user (User A & User B). What is happening, when User A locks the fields User B can unlock field by entering his/her password.

Is there any way so that if fields are locked by User A's password it will be unlocked only by User A's password. Same thing for User B's also.

Bookmark for User A:

(function () {

     var f_prefix = "prod.";

    // Your chosen password goes here

    var pw = "rok123";

    // Get a reference to the first field in the group

    var f = getField(f_prefix).getArray()[0];

    //Determine new readonly state, which is the opposite of the current state

    var readonly = !f.readonly;

    var readonly_desc = readonly ? "lock" : "unlock";

    //Prompt user for the password only if unlocking

   if (f.readonly) {

    var resp = app.response({

        cQuestion: "To " + readonly_desc + " the fields, enter the password:",

        cTitle: "Enter password",

        bPassword: true,

        cLabel: "Password"

    });

   } else {

       var resp = pw;

   }

    switch (resp) {

    case pw:

        getField(f_prefix).readonly = readonly;

        app.alert("The fields are now " + readonly_desc + "ed.", 3);

        break;

    case null:  // User pressed Cancel button

        break;

    default:  // Incorrect password

        app.alert("Incorrect password.", 1);

        break;

    }

})();

Bookmark for User B:

(function () {

    var f_prefix = "prod.";

    // Your chosen password goes here

    var pw = "sam789";

    // Get a reference to the first field in the group

    var f = getField(f_prefix).getArray()[0];

    //Determine new readonly state, which is the opposite of the current state

    var readonly = !f.readonly;

    var readonly_desc = readonly ? "lock" : "unlock";

    //Prompt user for the password only if unlocking

   if (f.readonly) {

    var resp = app.response({

        cQuestion: "To " + readonly_desc + " the fields, enter the password:",

        cTitle: "Enter password",

        bPassword: true,

        cLabel: "Password"

    });

   } else {

       var resp = pw;

   }

    switch (resp) {

    case pw:

        getField(f_prefix).readonly = readonly;

        app.alert("The fields are now " + readonly_desc + "ed.", 3);

        break;

    case null:  // User pressed Cancel button

        break;

    default:  // Incorrect password

        app.alert("Incorrect password.", 1);

        break;

    }

})();

Any help please.

TOPICS
PDF forms

Views

1.8K

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 , Jun 25, 2018 Jun 25, 2018

You would need to save the information somewhere, then, for example in a (hidden) text field.

Set its value to "A" if user A locks the file, and then reset it when they unlock it, and the same with B.

Then you add a condition to both scripts checking that field's value before allowing them to unlock the fields.

Votes

Translate

Translate
Community Expert ,
Jun 25, 2018 Jun 25, 2018

Copy link to clipboard

Copied

What are the names of the fields for each user?

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
Participant ,
Jun 25, 2018 Jun 25, 2018

Copy link to clipboard

Copied

Field names are prod.product, prod.name, prod.details, prod.invest, prod.fhsdt, prod.id, prod.witname, prod.remidial.

Either user A or B can fill this fields from production department and send this to QA department. For QA dept. I am thinking of using button.

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 ,
Jun 25, 2018 Jun 25, 2018

Copy link to clipboard

Copied

So you want to disable user B from unlocking the fields if user A locked them (and vice versa), basically?

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
Participant ,
Jun 25, 2018 Jun 25, 2018

Copy link to clipboard

Copied

Yes you are right.

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 ,
Jun 25, 2018 Jun 25, 2018

Copy link to clipboard

Copied

You would need to save the information somewhere, then, for example in a (hidden) text field.

Set its value to "A" if user A locks the file, and then reset it when they unlock it, and the same with B.

Then you add a condition to both scripts checking that field's value before allowing them to unlock the fields.

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
Participant ,
Jun 25, 2018 Jun 25, 2018

Copy link to clipboard

Copied

It would be great help if u give an example so that I can move forward.

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
Participant ,
Aug 04, 2018 Aug 04, 2018

Copy link to clipboard

Copied

LATEST

Hi

I have prepared my form in LCD, since I could not put the condition in acroform. In Xfa form, I used your logic and it worked absolutely!

You are a genius!

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