Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can JavaScript be used to add actions?

Explorer ,
Nov 21, 2021 Nov 21, 2021

I have a mass update that I'm trying to avoid having to do manually.

 

Is it possible to push an action onto an existing field?

 

Specifically;

loop for all fields {
    if (discriminate for fields I want){
        update fields 'mouse up' action to 'run JS' (I have set it up that 
        they can all use the same code).
    }
}
TOPICS
How to , JavaScript , PDF forms
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
2 ACCEPTED SOLUTIONS
Community Expert ,
Nov 22, 2021 Nov 22, 2021

Use the method setAction.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2021 Nov 22, 2021

for (var i = 0; i < this.numFields; i++) {

var oFld = this.getField(this.getNthFieldName(i));
if (oFld.type == "text") {
oFld.setAction("MouseUp", "run-JS();");
}

}


Acrobate du PDF, InDesigner et Photoshoptographe

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2021 Nov 22, 2021

Use the method setAction.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 22, 2021 Nov 22, 2021

for (var i = 0; i < this.numFields; i++) {

var oFld = this.getField(this.getNthFieldName(i));
if (oFld.type == "text") {
oFld.setAction("MouseUp", "run-JS();");
}

}


Acrobate du PDF, InDesigner et Photoshoptographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 23, 2021 Nov 23, 2021

Thank you both!

 

I'd found setAction in the documentation but not run-JS(). I was worried that I was in for a good 4+ hours of manual copy-pasting there. :S

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2021 Nov 24, 2021

Use a document level function. When you must change the script you must only change the function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 24, 2021 Nov 24, 2021

Yeah, the code body is all in doc level functions. What I specifically needed was to allow all fields of a specific type (that I can discriminate for by naming convention) to call a function when clicked. The code that I was inserting was just:

buildingClicked(event.target.name);

With 'buildingClicked' being an alternate entry to the main code. The 'main' method of input until this was 2 dropdowns, where input values were taken from the values of those boxes. This update allows users to click a box directly and input the other value via a popup.

 

Problem was, there are ~200 fields I wanted to add this too, so doing it manually was not really gonna happen!

 

Sometimes I find the ref docs really useful, other times almost misleading, so really appreciate the help clarifying, thank you. 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 24, 2021 Nov 24, 2021

It was you who put "run-JS" in your request, I thought it was a function that you had create.

Jut remove "run-JS" and replace it with your script.


Acrobate du PDF, InDesigner et Photoshoptographe
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 24, 2021 Nov 24, 2021

Oh I see now. Thanks, that's actually making sense with the documentation now. A roundabout way but I got there!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 24, 2021 Nov 24, 2021
LATEST

ugh, can't edit but yes, sorry I kinda had that in the original post. I meant it in simplified English terms, rather than literal though. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines