Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Need JScript fix: Alert box cancel button not working!

Avatar

Level 3

Hello all,

My form has an option for the user to delete subforms/records as needed. Acrobat does allow for Undo- so if my user accidentally clicks "delete", they're stuck.

I added an alert box to ask "Are you sure...", with "yes" and "cancel" buttons.  But when I click the cancel button, it deletes anyway!

Here is the script I'm using:

if(xfa.host.messageBox("Are you sure you want to delete? This cannot be undone.","Confirmation Required !!!",2,2)==4)

{

     xfa.host.Delete.click();  

}

else

{

     xfa.host.cancel.Action=2;

}

and here's the form:

Dropbox - AFBS_90-Plus_110614.pdf

Many thanks!

Laura

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

your script makes no sense to me.

Replace it with


if (xfa.host.messageBox("Are you sure you want to delete? This cannot be undone.", "Confirmation Required !!!", 2, 2) === 4) {


     _SummarySub.removeInstance(this.parent.index);


     if (xfa.host.version < 8) {


  xfa.form.recalculate(1);


  }


}


View solution in original post

7 Replies

Avatar

Correct answer by
Level 10

Hi,

your script makes no sense to me.

Replace it with


if (xfa.host.messageBox("Are you sure you want to delete? This cannot be undone.", "Confirmation Required !!!", 2, 2) === 4) {


     _SummarySub.removeInstance(this.parent.index);


     if (xfa.host.version < 8) {


  xfa.form.recalculate(1);


  }


}


Avatar

Level 3

OMG, I see it now! You are fabulous as always, radzmar.

I think I even understand why the previous made no sense!

Thank you a thousand times, this worked beautifully.  Someday I hope to find a class in javascript for Livecycle.

Best regards,

Laura

Avatar

Level 3

Hi radzmar, I want to apply a similar function to a message box. When the user clicks on 'submit' to attach the form to an email I want to ask them if they're sure the form is complete. This is OK if they choose yes, the form attaches to the email, but it also attaches to an email if 'no' is chosen. What do I need to include to cancel the email and return to the form if they choose no. Thanks.

Avatar

Level 10

What kind of button do you use?

Avatar

Level 3

An 'Email Submit Button' - submit as PDF

Avatar

Level 10

Ok, a submit button doesn't use a custom script to execute the submitting of the form or its data. So, to cancel the the submitting you have to use a script in the preSubmit event.

if (xfa.host.messageBox("Are you sure you want to send the form?", "Send form?", 2, 2) !== 4) { 

  xfa.event.cancelAction = true; // Cancel sending process if user selects not 'Yes'

}

Avatar

Level 3

That's brilliant - thanks radzmar!