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

Spawn/Delete Functionality to an App.Alert

New Here ,
Oct 03, 2018 Oct 03, 2018

Copy link to clipboard

Copied

I'm using a bit of complex code (and I'm trying to stay away from global variables) to have a checkbox within an app.alert window that upon click wound spawn a template. I have both codes (one for the app.alert with checkbox, and one for the spawn/delete) but cannot seem to link the two together well. Any help would be greatly appreciated.

App.Alert Code [Based on a dropdown value] :

{var oCk = {cMsg:"Yes, I want to add a form to this document", bInitialValue:true, bAfterValue:false};

    app.alert({cMsg:" Do you want to add a form to this document?", nIcon:3, oCheckbox:oCk, cTitle:"TDR?"});

    }

Spawn/Delete Code [To be triggered upon click of app.alert check]:

if (this.getField("Checkbox").value == "Off")

{

    oFld = this.getField("Additional NotesComments");

    this.deletePages(oFld.page[1]);

}

else

{

    var a = this.getTemplate("Form");

    a.spawn(1, false, false);

}

Let me know if you can help!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

565

Translate

Translate

Report

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

Community Expert , Oct 03, 2018 Oct 03, 2018

Like this:

if (app.alert("Do you want to add a form to this file?",2,2)==4) {

    // put code to spawn page here

}

Votes

Translate

Translate
Community Expert ,
Oct 03, 2018 Oct 03, 2018

Copy link to clipboard

Copied

You'll be better off using a "Yes/No" alert, instead.

On 4 October 2018 at 00:55, jonathanm75257324 <forums_noreply@adobe.com>

Votes

Translate

Translate

Report

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
New Here ,
Oct 03, 2018 Oct 03, 2018

Copy link to clipboard

Copied

Any insight on how to do it as a yes/no alert would be greatly appreciate. My main issue is linking the code.

Votes

Translate

Translate

Report

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 03, 2018 Oct 03, 2018

Copy link to clipboard

Copied

Like this:

if (app.alert("Do you want to add a form to this file?",2,2)==4) {

    // put code to spawn page here

}

Votes

Translate

Translate

Report

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
New Here ,
Oct 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

Thanks, that worked well.

One more caveat, I would like the alert to come up on only certain values (5 of them) within the dropdown list of 10. How would I do that?

Votes

Translate

Translate

Report

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 04, 2018 Oct 04, 2018

Copy link to clipboard

Copied

Did you attach the code to the drop-down's Validation event?

Votes

Translate

Translate

Report

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
New Here ,
Oct 05, 2018 Oct 05, 2018

Copy link to clipboard

Copied

I did not. It is set as a MouseUp action. Which do you recommend and what would the code be? Thanks.

Votes

Translate

Translate

Report

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 05, 2018 Oct 05, 2018

Copy link to clipboard

Copied

Use something like this as the custom validation script of the field:

if (event.value=="Value 1" || event.value=="Value 2" || event.value=="Value 5") {

    if (app.alert("Do you want to add a form to this file?",2,2)==4) {

        // put code to spawn page here

    }

}

Votes

Translate

Translate

Report

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
New Here ,
Oct 05, 2018 Oct 05, 2018

Copy link to clipboard

Copied

That worked well!

Would there be a way for the spawned page to only show up once? Either in the app alert or put in a max spawn page rule somehow.

Thanks.

Votes

Translate

Translate

Report

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 05, 2018 Oct 05, 2018

Copy link to clipboard

Copied

Sure, you can add something like this to the current code:

if (this.numPages<6) {

... // spawn page

} else app.alert("You may only add the form once.");

Votes

Translate

Translate

Report

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
New Here ,
Oct 05, 2018 Oct 05, 2018

Copy link to clipboard

Copied

That didn't seem to work. For more context, if the user selected a dropdown option that would trigger the app.alert, said yes and spawned the additional form, I would not want them to be able to add an additional form if they were to make a new selection (even if they say yes)

Votes

Translate

Translate

Report

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 05, 2018 Oct 05, 2018

Copy link to clipboard

Copied

Yes, I understood... Where did you place the code? Did you adjust the

allowed number of pages (I just entered 6 as a sample)?

On 5 October 2018 at 23:56, jonathanm75257324 <forums_noreply@adobe.com>

Votes

Translate

Translate

Report

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
New Here ,
Oct 05, 2018 Oct 05, 2018

Copy link to clipboard

Copied

I placed it where the original spawn page went:

    if (this.numPages<1) {

    var a = this.getTemplate("TDR");

    a.spawn(1, false, false);

    } else app.alert("You may only add the form once.");

Votes

Translate

Translate

Report

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 05, 2018 Oct 05, 2018

Copy link to clipboard

Copied

How can the number of pages in the file be less than 1?

Votes

Translate

Translate

Report

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
New Here ,
Oct 05, 2018 Oct 05, 2018

Copy link to clipboard

Copied

Ok. I switched it to 2. As shown below. Still no luck.

if (this.numPages<2) {

    var a = this.getTemplate("TDR");

    a.spawn(1, false, false);

    } else app.alert("You may only add the form once.");

Votes

Translate

Translate

Report

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 05, 2018 Oct 05, 2018

Copy link to clipboard

Copied

How many pages are there in the file before the form is added?

Can you share the file?

Votes

Translate

Translate

Report

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
New Here ,
Oct 05, 2018 Oct 05, 2018

Copy link to clipboard

Copied

I cannot share the file, unfortunately. Its a consolidated form with 4 subforms based on checkboxes. At its maximum its a 7 page document. Page 1 and 7 are always the same, the middle depends on order and number of selection. This would be a 5th sub form added.

I would prefer it to be always after page 1 if spawned.

Votes

Translate

Translate

Report

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 06, 2018 Oct 06, 2018

Copy link to clipboard

Copied

LATEST

Change the first line to:

if (this.numPages<7) {

Votes

Translate

Translate

Report

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