Expand my Community achievements bar.

SOLVED

Locking dynamic forms

Avatar

Former Community Member

I have created a form that allows for the user to enter in information on a customer and add fields as they are needed for the day.  I also added on a "Lock All Fields" button so that at the end of the day, no changes can be made to the form.  My problem is that when they click the button and save, the fields are locked, but when you re-open the form, the fields are all unlocked and editable again.  It saves all the data entered, it just doesn't permanently lock the form.  Does anyone know of a way to lock the fields permanently?

The script I use is:

form1.#variables[0].myScriptObject - (JavaScript, client)

/*************************************************************************************

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;

 

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

 

                              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

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

This is one of Paul's most popular scripts.

The trick here is to go to the File > Form Properties > Defaults dialog and make sure that Preserve Script Changes is set to Automatic:

Preserve script changes.png

That should fix it,

Niall

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

This is one of Paul's most popular scripts.

The trick here is to go to the File > Form Properties > Defaults dialog and make sure that Preserve Script Changes is set to Automatic:

Preserve script changes.png

That should fix it,

Niall