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

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

Community Beginner ,
Oct 07, 2016 Oct 07, 2016

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?

TOPICS
Acrobat SDK and JavaScript , Windows
2.4K
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

correct answers 1 Correct answer

Engaged , Oct 07, 2016 Oct 07, 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-

Translate
Engaged ,
Oct 07, 2016 Oct 07, 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-

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 Beginner ,
Oct 08, 2016 Oct 08, 2016

Thanks J,

Sounds simple enough, I will give it a try on Monday.

Rob

Sent via the Samsung Galaxy Note5, an AT&T 4G LTE smartphone

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 Beginner ,
Oct 10, 2016 Oct 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 ]

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 ,
Oct 10, 2016 Oct 10, 2016

That's not how you access fields in Acrobat JS.

You can use this code instead:

event.target.readonly = true;

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 Beginner ,
Oct 10, 2016 Oct 10, 2016

As I said I have very little experience with javascript, and I was pretty sure the naming I used wasn't going to work, but for whatever reason just putting the string you gave me at the end did not work either. It kept giving me a syntax error no matter how I tried to put it in. Instead of trying to figure out how I was messing up the insertion of your string into the existing string I decided to try another approach.

What I did was separate the actions, spawning the page on a mouse down action and making the button read only on the mouse up action. Using the string you gave me for the mouse up action worked perfectly in this manner. I have now programmed all of the one time use buttons in the report and they are all working flawlessly, even the buttons that are generated on the spawned pages.

Thanks for the help. I would still be searching for the proper script, and getting very frustrated, without you leading me to the water hole.

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 ,
Oct 10, 2016 Oct 10, 2016

Post the full code you're currently using, as well as the error message you're getting.

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 Beginner ,
Oct 10, 2016 Oct 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.

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 ,
Oct 10, 2016 Oct 10, 2016

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

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 Beginner ,
Oct 10, 2016 Oct 10, 2016

The auto spacing seems to only exist in the email, which is where I copied Joel’s original code from before pasting it into the javascript window in Acrobat.

This is the only explanation I can easily come up with for the syntax error I was getting since it seems that I was placing the string into the code correctly. Regardless I did a test and typed the code in and pasted Joel’s code from the online thread with no issues. I then copied and from his email and from your email and got the same syntax error, but it also worked once in awhile.

This issue is resolved and I have the form doing what I need it to do.

Thanks for your help on this.

Best regards,

Rob Kerr

Technical Writer

[ Mod: Personal information removed ]

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
Engaged ,
Oct 10, 2016 Oct 10, 2016

Glad you got it working. I was offline all weekend.

J-

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 Beginner ,
Oct 10, 2016 Oct 10, 2016
LATEST

No problem.

Obviously I had some issues with the way I cut and pasted the code, and my attempts to reinterpret your instructions made things worse. A little pushing from another commenter got me to realize it wasn’t the code and after that I was able to get it all figured out and working.

Thanks again for the help.

Best regards,

Rob Kerr

Technical Writer

[ Mod: Personal information removed ]

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