Skip to main content
New Participant
January 27, 2024
Question

Hide all fillable form buttons with a password

  • January 27, 2024
  • 1 reply
  • 336 views

Hi all,

 

I have not long started using JavaScript in my fillable forms, I have found the below script online that locks all fillable fields after a button is pressed & a password is entered correctly

 

(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., "SITE.NAME")

  var f_prefix = "SITE";

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

  var resp = app.response({

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

    cTitle: "Enter password",

    bPassword: true,

    cLabel: "Password"

  });
  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;

  }


})();

 

I would like to do the same to hide all buttons on the form when a button is pressed & a correct passwords is entered, all I have found so far is the below script to hide the buttons which works as it should but no password option.

 

for (var i=0; i<this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

    if (f==null) continue;

    if (f.type=="button") f.display = display.hidden;

}

 

Would it be possible to add making the buttons on the form hidden to the original script I am using, if not add a password option to the script to hide the buttons?

 

Also, can it be set up so the buttons don't print either?

 

Any help would be appreciated

 

Thanks in advance

This topic has been closed for replies.

1 reply

Nesa Nurani
Community Expert
January 28, 2024

If you use display.hidden buttons will be hidden and won't print, if you use display.noPrint buttons will be visible but won't print.

Use this script to ask for password, if password is correct it will hide buttons if not it will pop alert saying "Password is not correct", change "Your Password" to whatever you wish password to be:

var cRtn = app.response ({ cQuestion:"Enter the password", bPassword:true}); 
if(cRtn == "Your Password"){
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f==null) continue;
if (f.type=="button") f.display = display.hidden;}}
else
app.alert("Password is not correct.");

 

New Participant
January 28, 2024

Thank you for your reply Nesa,

 

i managed to get the original field readonly script working to hide the buttons as required late last night, do you or anyone know if it would be possible to have one script like the original I posted so it makes selected fields readonly & selected buttons hidden all in one script so only one button is required?