- Creating variables in the File > Form Properties > Variables tab.
- Creating a form variable in JavaScript.
- Select the Subform > Right Click > Insert Script Object
- A Button
- A Script Object
Here:
myScriptObject is a ScriptObject with function called LockAllFields and parameter form1 is the form name where the lock operation will occur.
1. Add a button field and change the Caption to Lock All Fields and in the click event type the following javascript code:
myScriptObject.LockAllFields(form1);
2. Select the Subform what contains all the buttons including Lock All Fields and Insert ScriptObject > Rename the Script Object to myScriptObject and type the following javascript code:
/*************************************************************************************
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
3. If you want to protect any control field from locking then insert a Subform and put that control filed into newly created Subform
No comments:
Post a Comment