Skip to main content
Participant
February 21, 2018
Question

Lock/Unlock Button - Password Sync Issues

  • February 21, 2018
  • 1 reply
  • 683 views

Hi all,

Need some help from someone who knows their stuff...

I've got a Interactive PDF that has a script set to a button where it locks certain fields, unless you know the password to make all fields editable. It's the same script that's on this help forum elsewhere. I need to take it a step further however, but I don't know how. I get the general gist of what I need to do, just don't know how to execute it.

My problem is my button has two states; a 'Locked' (red) state and 'Unlocked' (green) state. I need to know how to sync up the code so that if you click the button to unlock, then cancel the password prompt, that the button doesn't continue to switch to the 'unlock' state with it still being locked.

For example;

  • the button is currently red (locked)
  • you click the button to unlock, and the password prompt box comes up
  • you cancel that prompt
  • the button then switches to show the green (unlocked) state, even though it is still locked.

Is there a way to edit the script (below) so that it always knows what state the button is in, and reacts accordingly. So in the locked state, always asks for the password and in the unlocked state always locks the fields?

Any help would be great,

Thanks

----

The script i'm using is as follows:

(function () {

    // Prefix for group field names. Change to match what you want to use.

    // Rename the fields you want to lock to match this prefix (e.g., "PRIV.NAME")

    var f_prefix = "PRIV";

    // Your chosen password goes here

    var pw = "1234";

    // 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;

    }

})();

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
February 22, 2018

You say that the button has two states, but I don't see anywhere in the code where you change from one state to the other, so how is it done?

Participant
February 22, 2018

Hi Try67,

That's my issue I don't know what code to place and where, as I'm learning as I go along!

Let's for arguments sake say my button is called 'Unlock_Button' and has two states. How could I modify the javascript to include the button?

Currently I have the button set-up in indesign, and adding the code to it in Acrobat.

Thanks

Legend
February 22, 2018

Acrobat doesn’t have multistate buttons. Two popular tricks to seem to do this are

1. Two buttons in the same space. You arrange (in your code) that one is always visible and one is always Hidden. Recommended. 

2. Loading separate images as icons. Best avoided if you are new to this.

If InDesign makes multistate buttons it will probably be doing something clever and too complicated to follow and adapt.

If you don’t know WHERE to put code it means you don’t understand the flow of the code. You absolutely need this before you can adapt even if you don’t follow every line in it. Focus on understanding the flow next. Especially work on pairing up braces {...}