Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Scripting error changing field required state

Avatar

Not applicable
I need to update all fields in a document to be not required. I read the value but cannot set it. I get the following error in the debugger.



NotAllowedError: Security settings prevent access to this property or method.

Field.required:10:click undefined:Exec



According to the documentation, this should be easy to do.

--------------------------------------

required



Sets or gets the required characteristic of a field. When true, the fields value must be nonnull when the user clicks a submit button that causes the value of the field to be posted. If the field value is null, the user receives a warning message and the submit does not

occur.



Type: Boolean Access: R/W Fields: all except button.



Example

Make "myField" into a required field.

var f = this.getField("myField");

f.required = true;

--------------------------------------



I am not sure what this means or how to correct. Any help would be greatly appreciated. My code is below.



var fieldCount = event.target.numFields;

for ( var i = 0; i < fieldCount; i++)

{

var fieldName = event.target.getNthFieldName(i);

app.alert(fieldName);

var field = event.target.getField(fieldName);

if(field.type != "button" &&

field.type != "checkbox")

{

app.alert(field.required);

field.required = false;

}

}
3 Replies

Avatar

Not applicable
If you are designing your form in Designer and not Acrobat then you shouldn't be trying to change the property on the AcroForm object (ie: the fields you get from using event.target.getField()) but rather on the XFA object. Here is an example copied from the XML Form Object Model Reference that changes all fields to read only. You can modify this to achieve what you want. In your case you'll want to set the mandatory property to "disabled".



// Get the field containers from each page.

for (var i = 0; i < xfa.host.numPages; i++) {

var oFields = xfa.layout.pageContent(i, "field");

var nodesLength = oFields.length;

// Set the access type.

for (var j = 0; j < nodesLength; j++) {

var oItem = oFields.item(j);

if (oItem != this) {

oItem.access = "readOnly";

}

}

}



Chris

Adobe Enterprise Developer Support

Avatar

Not applicable
That helped. Thank you.



I have one more problem.



I have two buttons for submitting the form. One of the buttons (Complete) submits doing all validation. The other button (Save) submits but needs to turn of the mandatory field validation. I have tried putting this script in the click event of the Save button, but you cant have click event code in submit buttons. So my next option was to put the code in the preSubmit event. However, this fires for every submit. Is there a way to determine that the preSubmit event was caused by the Save button and not by the Complete button?

Avatar

Not applicable
Does it work if you put the code to turn off the mandatory field validation on the mouseDown event of the save button?



Chris

Adobe Enterprise Developer Support