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

I want a submit button which when clicked first lock the fields and if the button is clicked again then it ask for password to unlock all the fields

Engaged ,
Sep 28, 2016 Sep 28, 2016

Sir / Madam,

I want to make a submit button which when clicked would lock all the fields so that no editing can be done........... and if user again clicks the submit button then it should ask for password to unlock all the fields for editing.........and again user can edit the required fields.

Hope you got what i am trying to say.

TOPICS
Acrobat SDK and JavaScript , Windows
2.0K
Translate
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 , Sep 29, 2016 Sep 29, 2016

I assume you don't know what an anonymous JavaScript function is, and that's why you define one inside the "if" statement. You use such an anonymous function to create a private scope for variables, that otherwise would end up being global. If you want to use this mechanism, you need to pull out the function definition to the top level. Also, your code set the fields to writable regardless of the password entered. I moved a few things around, and this is working for me:

(function() {

    var isRea

...
Translate
Community Expert ,
Sep 29, 2016 Sep 29, 2016

Create a button action that first checks to see if one of the fields that can change state from editable to read-only and back. If that field is editable, then you run a loop over all fields (with the exception of your button) and sets the readonly property to true. If the field is already readonly, then put up an input window or a custom dialog that asks for the password and then runs the same loop as before, but sets the readonly property to false.

Translate
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
Engaged ,
Sep 29, 2016 Sep 29, 2016

I found out javascript for prompting for password.. but not able to lock the fields'

(function () {

// Get one of the fields in the group
var f = getField("private.name");

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

switch (resp) {

case "your_password": // Your password goes here
getField("private").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;
}

})();

Translate
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 ,
Sep 29, 2016 Sep 29, 2016

The following code will handle setting the fields to readonly and editable:

// get the status of one of the fields

var isReadOnly = this.getField("Text1").readonly;

if (isReadOnly) {

  // prompt for password

  // ... you already have code for that ...

  // ...

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

    var fieldName = this.getNthFieldName(i);

    if (fieldName != event.target.name) {

      this.getField(fieldName).readonly = false;

    }

  }

}

else {

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

    var fieldName = this.getNthFieldName(i);

    if (fieldName != event.target.name) {

      this.getField(fieldName).readonly = true;

    }

  }

}

Translate
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
Engaged ,
Sep 29, 2016 Sep 29, 2016

Thank you sir, this worked but  the field once locked... it remains locked.. i am not able to edit it after it is being locked even by providing password.

I want all the fields should be locked when action button is clicked and again.. when action button is clicked.. all the fields should automatically gets unlock for editing..

Translate
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 ,
Sep 29, 2016 Sep 29, 2016

Use just my script (change the one field name that gets referenced). Does that work? When you click the button once, all fields should get set to read-only, when you click again, they should be set to editable again. Now add your password support in the correct spot. You will need another if statement that checks for the correct password.

If this still does not work, please post the whole script you are using.

Translate
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
Engaged ,
Sep 29, 2016 Sep 29, 2016

var isReadOnly = this.getField("Text4").readonly; 

 

if (isReadOnly) { 

  (function () {

// Get one of the fields in the group

var f = getField("Text4");

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

});

switch (resp) {

case "123": // Your password goes here

getField("private").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;

}

})();

 

 

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

    var fieldName = this.getNthFieldName(i); 

    if (fieldName != event.target.name) { 

      this.getField(fieldName).readonly = false; 

    } 

  } 

else { 

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

    var fieldName = this.getNthFieldName(i); 

    if (fieldName != event.target.name) { 

      this.getField(fieldName).readonly = true; 

    } 

  } 

Translate
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 ,
Sep 29, 2016 Sep 29, 2016

I assume you don't know what an anonymous JavaScript function is, and that's why you define one inside the "if" statement. You use such an anonymous function to create a private scope for variables, that otherwise would end up being global. If you want to use this mechanism, you need to pull out the function definition to the top level. Also, your code set the fields to writable regardless of the password entered. I moved a few things around, and this is working for me:

(function() {

    var isReadOnly = this.getField("Text4").readonly;

    if (isReadOnly) {

        // Get one of the fields in the group

        var f = getField("Text4");

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

        });

        switch (resp) {

            case "123": // Your password goes here

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

                    var fieldName = this.getNthFieldName(i);

                    if (fieldName != event.target.name) {

                        this.getField(fieldName).readonly = false;

                    }

                }

                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;

        }

    } else {

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

            var fieldName = this.getNthFieldName(i);

            if (fieldName != event.target.name) {

                this.getField(fieldName).readonly = true;

            }

        }

    }

})();

Translate
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
Engaged ,
Sep 29, 2016 Sep 29, 2016

Thank you very much sir.. it worked like a gem..... thank you once again..........

Translate
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
Engaged ,
Sep 29, 2016 Sep 29, 2016

I have on more query.. if you don't mind.........

i have field in which Name of the person is entered.. ie. first name, middle name and last name.. all continously in one field.

I want to extract all the words.. in three different field in the same document.

Translate
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 ,
Sep 29, 2016 Sep 29, 2016

Bad idea. Many people have first names that are more than one word, or multiple last names, etc.. You're likely to make mistakes and make the users upset. If you want to save time do it the other way around: Have the users fill in the individual fields and then combine them to a single "full name" field.

Translate
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
Engaged ,
Sep 29, 2016 Sep 29, 2016

Sir,, the requirement is such that i have to extract the first name.......  because it is report card.. and the name is punched in the beginning of the form   and in the last two pages.. the review is given quoting their first name several times..around 20 to 25 times.. so to save time i want them to be automatically extracted from the first page.

Translate
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
Engaged ,
Sep 29, 2016 Sep 29, 2016

i have seen split() function is used in these type of work.

I just want to extract the first word before the first space..

Translate
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 ,
Sep 29, 2016 Sep 29, 2016

You're not saving time. You're creating problems for your self. Some people have more than one word in their first name ("John Baptiste", for example), and will be annoyed if you force them to use just the first one, as it's not their full name.

Instead, just duplicate the fields across the pages, and the user will only have to fill it in once, and then value will be automatically copied to the rest of them.

Translate
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
Engaged ,
Sep 29, 2016 Sep 29, 2016

then it will show the full name every where...

Translate
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 ,
Sep 29, 2016 Sep 29, 2016

I'm talking about the first name field. That's the one you want to appear

on all pages, no?

On Thu, Sep 29, 2016 at 7:31 PM, rakeshk21205956 <forums_noreply@adobe.com>

Translate
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
Engaged ,
Sep 29, 2016 Sep 29, 2016
LATEST

Name field contains the full Name on the first page..

Translate
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