4 Replies Latest reply on Nov 25, 2017 3:57 PM by awbrown66

    Use setAction without overwriting existing js

    awbrown66 Level 1

      I'm using the setAction to enter js for specific fields (see example below) I already have On Blur actions that exist for some of these fields that I do not wish to overwrite.... how do I add to an existing On Blur without overwriting?


      var reqFields = new Array("Text1", "Text2");
      for (i = 0; i < reqFields.length; i++) {
        • 1. Re: Use setAction without overwriting existing js
          try67 MVP & Adobe Community Professional

          Not possible.

          1 person found this helpful
          • 2. Re: Use setAction without overwriting existing js
            Thom Parker Adobe Community Professional

            Try is correct that when you overwrite an event script, it overwrites it. In addition to this, the event scripts can't be read. So to do this you would have to keep a copy of the original code in each script that will be overwritten, then build the final script from this.


            However, setting event scripts is a development activity.  This is not the type of thing you have in a working document. It you are trying to use "field.setAction()" to modify fields at run time, then you should find a different way accomplish your goal. 


            For example, include the complete code set into the event script, then use "if" statements to control which bits run.

            1 person found this helpful
            • 3. Re: Use setAction without overwriting existing js
              Joel_Geraci Adobe Community Professional

              This is why you never... never... never... put blocks of code in an action. Only put calls to functions into the actions tabs. Create a document level script that loads the functions when the document loads. That way you can easily edit what the events do without editing the code in the events themselves.


              Then you can do fun stuff like...


              this.getField("myField").setAction("doThis(event); thenThat(event);thenSomethingElse(event)");


              ... to chain together the functions that you need for that field event.



              1 person found this helpful
              • 4. Re: Use setAction without overwriting existing js
                awbrown66 Level 1

                Thanks, guys!  This document is in the re-development stage... I wasn't going to include this script in the final version of the user doc, I will use it only to add the same script to several fields, and this is the quickest and simplest way (as far as I know) to do it.


                I knew that it was possible to manually add more than one On-Blur trigger event to a field, so I was wondering if there was a way of replicating this with setAction or some other similar scripting method.


                My doc has approx. 25-30 fields that require the new On-Blur script (call to a doc level function), but there are approx. 5-8 fields with existing On-Blur triggers (call to other doc level functions) that I need to retain in addition to the new On-Blur function call.


                I thought I would check here first before I proceeded with the process...