Validate fields then lock
I've found a few conversations on validating but can't find any written resolutions other than "oh hey, I fixed it".
The code I use to lock the doc fields is:
var r = app.alert("Are you ready to lock this document?",2,2);
if (r == 4) { // 4 is Yes, 3 is No
for (var i = 0; i < this.numFields; i++) {
var fname = this.getNthFieldName(i);
this.getField(fname).readonly = true; // makes all fields readonly
}
}
A script I found to check validation looks like this:
// These are the required fields on the form.
// Populate array with their names.
var RequiredFields = new Array(3);
RequiredFields[0] = "Captain";
RequiredFields[1] = "Equipment";
RequiredFields[2] = "Date";
// These are the alert messages shown when a required field is empty.
// Populate array with messages.
// Make sure there's one message for each required field.
var alertMsg = new Array(3);
alertMsg[0] = "Please enter the name of the Captain.";
alertMsg[1] = "Please enter the Equipment ID.";
alertMsg[2] = "Please enter the Date.";
var bSuccess=True
var emptyTest = /^\s*$/;
var fieldCount = RequiredFields.length
var fld = 0;
for (var i=0; i < fieldCount; i++)
{
fld = this.getField(RequiredFields);
if( emptyTest.test(fld.value) ) // if required field is empty
{
bSuccess=false;
app.alert(alertMsg);
fld.setFocus();
break;
}
if(bSuccess)
this.mailDoc(true);
}
Any ideas how I can combine them so that it validates the 3 fields and if good asks if you want to lock it?
