Expand my Community achievements bar.

SOLVED

LockAllFields Script Help

Avatar

Former Community Member

Hi All,

Having some trouble with a LockAllFields script.

I'm trying to make a button which will lock all the fields on a form. I've been using the following script:

myScriptObject.LockAllFields(form1);

This is set to run on mouse up.

I've created a script object in the root (form1) and just called it myScriptObject

Do I need to do anything else with the object at all?

At the moment I'm getting the an error when I press the lock button in Reader (see attached)error.jpg

What do I need to do to get this working?

Many Thanks!

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Ok I think I have figured this out. The lock all fields is a red herring. That option you are using is simply adding a comment to the form. Comments cannot be added to a dynamic form. If you save your form as a static PDF then that technique will work whether the fields are locked or not.

Paul

View solution in original post

32 Replies

Avatar

Former Community Member

In reader I'm going to Document > Sign > Apply Ink Signature.

Avatar

Correct answer by
Former Community Member

Ok I think I have figured this out. The lock all fields is a red herring. That option you are using is simply adding a comment to the form. Comments cannot be added to a dynamic form. If you save your form as a static PDF then that technique will work whether the fields are locked or not.

Paul

Avatar

Former Community Member

Paul,

I think you've solved it. Just testing it now and if it works I'll let you know.

Thanks,

Chris

Avatar

Former Community Member

Paul,

Thanks for your help, really appreciate it. It seems to be working very well.

Just wondering though... is there a way I can hide a text box after the lock all fields button has been pressed? i.e. I've added a text box with instructions on how to lock the form and then sign it. I'd like these instructions to disappear after the form has been locked.

Is that possible?

Thanks again,

Chris

Avatar

Former Community Member

Yes ...simply use this command after the call to the lock fields script

TextFieldName.presence = "invisible"

Paul

Avatar

Former Community Member

Hi Paul,

I've renamed the fields that I want to hide as Instructions and Instructions2.

I added

Instructions.presence = "invisible"

Instructions2.presence = "invisible"

to the code in the button, so it looks like:

form1.#subform[5].Button4::click - (JavaScript, client)

 

myScriptObject.LockAllFields(form1);

Instructions.presence = "invisible"

Instructions2.presence = "invisible"

I can't get it to work when I preview the form. I haven't gone as far as testing it in reader yet.

Is the above correct? Do I need to add any code anywhere else, such as in the myScriptObject variables?

Thanks,

Chris

Avatar

Former Community Member

That is right ....make sure you save the form as dynamic. Also if it still does not work then hit the ctrl-j during preview and if you are using Acrobat the Javascript console will come up and report any scripting errors.

Paul

Avatar

Former Community Member

Paul,

In one of the last posts in this thread you told me to save the form as static, as it wasn't working when saved as dynamic.

Avatar

Former Community Member

Sorry ...answering so many questions I get the issues mixed up. Your code looks fine ...can you email the form to LiveCycle8@gmail.com so I can have a look?

Paul

Avatar

Level 1

Hello Paul, Hope you are in good spirits today..

I have a simple question I believe. (hopefully)

I am using your lock all fields script and it works great, however I would like to omit a single email submission button from this script. Can you explain how I would do that. This is a very basic, single page form.

The other option would be to add some code to the lock all fields button so it would mailto: after the form was locked.

Sorry if this has already been answered, I looked through the thread and didn't see anything about it.


Thanks so much!

Avatar

Former Community Member

No probs ....

In the function that locks all fields each object on the form is identified and checked for its clsssname  - if it is a field then we know that is one of the following (DDList, TextField, NumericField, radio button, checkbox , Button , etc...). We can do a subsequent check to see if it is a button. In my case a named all of my buttons Button1, Button2 etc... so I simply choose each object with a classname of field and a name that has Button for its first 6 chars and I omit that from the lock procedure. I included a modified sample to give you the idea as well here is the modified script object  that I used:

/*************************************************************************************
Function: LockAllFields
Description: This function will lock all fields.
IN: The parent subform. It could also be an element that contains subform like form1
OUT : nothing
**************************************************************************************/
function LockAllFields(myParentObject){

var allChildElements;
var intNumElements;
var currentElement;
var j;
var temp;

//Get all the child nodes of the parent element
allChildElements = myParentObject.nodes;

//Total number of element in the object
intNumElements = allChildElements.length;

//Loop through all the child elements
for(j=0; j< intNumElements;j++){
  currentElement = allChildElements.item(j);
  //If the element is another subform we'll recusively call the function again
  if(allChildElements.item(j).className == "subform"){
   LockAllFields(currentElement);
  }
  //If the objects are fields and they are set to mandatory (validate.nullTest) then we will set the border.fill.color - dependant on object type
  else if(currentElement.className == "field"){
   //CHeck to see if the field is a button - do not lock buttons
   temp =  currentElement.name;
   if (temp.substring(0,6) != "Button"){
    currentElement.access = "readOnly";
   }
  
  }
   //Check for exclusion groups - Radio Buttons
   else if(currentElement.className == "exclGroup"){
   for(k=0; k< currentElement.nodes.length;k++){
    if(currentElement.nodes.item(k).className == "field"){
     //set the color for the radio buttons individually
     currentElement.access = "readOnly";
    }
  
   }
  }
}
}//end function

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----