Skip to main content
Participating Frequently
October 7, 2016
Answered

I need to disable a button after it has been clicked and spawned a template

  • October 7, 2016
  • 1 reply
  • 2797 views

I have little experience writing java script, but I am pretty sure I need to use java script to disable an add page button after it has been clicked and spawned it's assigned template. The java script I am using to spawn the template is as follows.

var expTplt = getTemplate("tpltReport");

expTplt.spawn(2,true,false);

This script works fine, and I have created several identical templates with different names so that a specific template is launched when the add page button is clicked on specific page of the pdf. This is to prevent the information that is entered on one page from being repeated on all the subsequent pages that are added to the pdf. I rename the effected fields on each template to accomplish this.

Since each template has its own add page button, with the exception of the final template, if one is clicked multiple times from the same page it will spawn multiple identical pages and the repeating information error will occur.

Any simple solutions?

This topic has been closed for replies.
Correct answer JoelGeraci_Datalogics

Add the following line to the end of your script so so that the button being pressed is the one that runs the script. Setting a button to read-only makes it disabled. The event is the click, the target is the object that triggered the event... in your case, the button, regardless of the number of times it gets renamed due to the spawn process.

event.target.readonly = true;

J-

1 reply

JoelGeraci_Datalogics
JoelGeraci_DatalogicsCorrect answer
Participating Frequently
October 7, 2016

Add the following line to the end of your script so so that the button being pressed is the one that runs the script. Setting a button to read-only makes it disabled. The event is the click, the target is the object that triggered the event... in your case, the button, regardless of the number of times it gets renamed due to the spawn process.

event.target.readonly = true;

J-

Participating Frequently
October 10, 2016

HI Joel,

I am getting a syntax error (SyntaxError: missing ; before statement 3: at line 4).

Below is how the string reads after adding your suggestion at the end of the script. Maybe I am not understanding what your are telling me to do.

var expTplt = getTemplate("tpltReport");

expTplt.spawn(2,true,false);

click.Add Page1.readonly = true;

Thoughts?

Best regards,

Rob Kerr

Technical Writer

[ Mod: Personal information removed ]

try67
Community Expert
October 10, 2016

This is the code I am using for the mouse down action:

var expTplt = getTemplate("tpltReport");

expTplt.spawn(2,true,false);

I am using the code you and Joel gave me for the mouse up action:

See my 5:34am response for the error I was getting, but this is basically the code I started out with:

var expTplt = getTemplate("tpltReport");

expTplt.spawn(2,true,false);

event.target.readonly = true;

Everything after that was some sort of slight variation of this, including the renaming to match the events and actions this code actually affected.

One observation though, the original string, sent by Joel, seems to include auto spacing below the text when highlighted, the code you sent does not show auto spacing when highlighted. Originally I cut and pasted Joel's code into the javascript window to change the code, I wonder if the auto spacing was what was injecting the syntax error?

When I separated the actions I just typed in the code you and Joel gave me and have had no problems.


I'm not sure what "auto spacing" you're referring to, but the code above does not have any syntax errors in it.