Copy link to clipboard
Copied
Is there something odd about making required fields in Acrobat 2017.
I want to test for required fields when using the File Save menu, not under a button.
Tried code below, used to work in acrobat XI.
Ideas?
function validateFields()
{
//a counter for the number of empty fields
var flg = 0
// count all the form fields
var n = this.numFields
//create an array to contain the names of required fields
//if they are determined to be empty
var fArr = new Array();
//loop through all fields and check for those that are required
// all fields that have a '*' in their tool tip are required
for(var i = 0;i<n;i++){
var fn = this.getNthFieldName(i);
var f = this.getField(fn);
//tool tip is the fields\'s 'userName' property;
var tt = f.userName
//test for the '*';
if(tt.indexOf('*')!=-1 && f.value == f.defaultValue){
//increment the counter of empty fields;
flg++;
//add the fields userName (tool tip) to the list of empty field names;
fArr[fArr.length] = tt;
}
}
//now display a message if there are empty fields
if(flg>0){
app.alert('There are '+flg+' fields that require a value\n\n'+ fArr,3)
}
else{
this.save();
}
}
Copy link to clipboard
Copied
Nothing has changed.
Copy link to clipboard
Copied
Nothing has changed.
Copy link to clipboard
Copied
Ok thanks, so this code was for a button. Is there some code that is based on the File Save? So no button, but if Save or Save As is used, it tests for required?
Copy link to clipboard
Copied
Yes, the code was for a button.
Copy link to clipboard
Copied
What about no button at all. When you go File Save, if the field is blank you get a popup to complete field?
Copy link to clipboard
Copied
You can do that, but you can't prevent the file from being saved.
Copy link to clipboard
Copied
do you mean I would get the pop up, and it would also save? Defeating the purpose?
Copy link to clipboard
Copied
Defeating your purpose, not the user's...
You can force the saved copy to be blank, though, or to contain a large
error message.
Copy link to clipboard
Copied
ok, so I am not seeing a fix here.
confusing......I can force it to be saved blank or contain a large error message??
No idea what to do with this....
Copy link to clipboard
Copied
Thanks anyways.....