Skip to main content
MADink_Designs27
Inspiring
March 23, 2017
Answered

NotAllowedError: removeField action on button mouse-up

  • March 23, 2017
  • 2 replies
  • 3167 views

Is this.removeField or something else in the below script a trusted function?

I'm trying to create a button that will delete fields by type. I want the button to delete buttons, checkboxes, and radio buttons.

I already have this as an action and it works, but I'd like it as a button for easy access and for other users to use.

I'm getting the following error: NotAllowedError: Security settings prevent access to this property or method. Doc.removeField:11:AcroForm:MouseUp:Action1

Below is the script I've modified from another forum, but can't seem to find the link to reference. The only difference is I added the or operand to find multiple field types. It's set to a mouse-up event. I've also tried putting most of it document level except for the last for condition and the delete button action., but that still produces the error. Additionally, I tried this.removeField with a named field and it works. I guess I'm not seeing anything that would require a trusted function...

//Remove Buttons and Checkboxes

var fields = new Array();
for ( var i=0; i<this.numFields; i++)
{
var fname = this.getNthFieldName(i);
if ((this.getField(fname).type == "button" || this.getField(fname).type == "checkbox" || this.getField(fname).type == "radiobutton"))
{
fields.push(fname);
}
}

for (var i=0; i<fields.length; i++)
{
this.removeField(fields);
}

This topic has been closed for replies.
Correct answer try67

I'm running Acrobat Pro DC.

It's strange that the code works in an Acrobat Action but seems to produce an error when ran via mouse-up.

There are several fields with the same name for text field duplication and to keep the file lighter and less complicated.

On a side note, I was under the impression that Reader DC no longer needed usage rights enabled...


Not for saving filled-in forms, but it does require it for executing some JS commands.

So this is happening when you run the code in Acrobat, from a button? Could it be that you're trying to delete the button that triggered this code? That would be a problem, as it's still being used at that moment.

2 replies

Participant
October 31, 2019

I used the same code (this.removeField(fields);) in my Javascript which was attached to a Button, and yes I was removing that same Button.  In Adobe Acrobat Pro 9 my Javascript worked fine; that Button was removed.  However when I upgraded to Pro DC then I got that same error message.  For the last week I was trying to figure out how I could change my security settings to eliminate that error.

 

When I read this post I realized I did not have to remove the Button field, just make them hidden.  My goal is to flatten all the form fields and eliminate all the Button fields.  When I  changed the code to f.display = display.hidden;, my Javascript worked in Pro DC.  Once I flattened the document the Button fields were completely gone.

I still think there must be a way to change the security settings so that I could remove the field with Javascript.  It still works fine in Acrobat 9 Pro.   This is why I have some hesitation when it comes to upgrading. 

I hope that my other Javascripts will continue to work without and debugging.

Thanks for this Post

 

Bernd Alheit
Community Expert
Community Expert
October 31, 2019

What happens when you use the code in the console?

MADink_Designs27
Inspiring
March 23, 2017

Update: it seems to be doing part of the function and then stopping with the error. I tried another version with only deleting buttons and it deleted some but not others.

try67
Community Expert
Community Expert
March 23, 2017

- No, you don't need a trusted function to run this code. However, if you want to use it in Reader then the file must have Form Usage Rights applied to it. Are you running this code in Reader?

- Yes, when an error is encountered (and not caught) the script will stop executing immediately.

MADink_Designs27
Inspiring
March 23, 2017

I'm running Acrobat Pro DC.

It's strange that the code works in an Acrobat Action but seems to produce an error when ran via mouse-up.

There are several fields with the same name for text field duplication and to keep the file lighter and less complicated.

On a side note, I was under the impression that Reader DC no longer needed usage rights enabled...