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

Testing for the user cancelling a dialog

Participant ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

Hi there, please can someone help me with a question about the user cancelling a dialog?

 

I have a js process that works ok.

What I'm having a problem with is the user cancelling a dialog.

 

var exitDialog = 0; 
while (exitDialog !=999)
    	{ 
    		var cRtn = app.response("How many checkboxes would you like (1-9) ?");
    	    	if (cRtn > 0 && cRtn < 10)
   	    	    	{
       		    	    	var exitDialog = 999;
    	    	    	}
    	    	else 
    	    	    	{
    	    		    	if (cRtn == null) {break;}
    		    			app.alert('Please enter a value from 1-9');
    		    	}
    	}
// the rest of the process happens here and that works ok.

I can run the code above and it works fine apart from if the user cancels the dialog.

If I run the code above in the debugger it works ok. When I load it as a custom menu item it still works ok until the user cancels.

What I'm trying to do is allow the user to cancel the operation by pressing the 'Cancel' button on the dialog.

 

Please can someone point me in the right direction?

 

Thank you 🙂

 

TOPICS
Acrobat SDK and JavaScript , Mac

Views

147

Likes

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 , Aug 25, 2021 Aug 25, 2021

Move the check whether cRtn is null above the other conditions.

Also, move the alert command above the break command, as it will never be reached if it's after it.

Likes

Translate

Translate
Community Expert ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

Move the check whether cRtn is null above the other conditions.

Also, move the alert command above the break command, as it will never be reached if it's after it.

Likes

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
Participant ,
Aug 25, 2021 Aug 25, 2021

Copy link to clipboard

Copied

Thanks for the speedy response 🙂

I'll re-jig things as per your post.

Likes

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
Participant ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

Hi there,

Think I'm still doing something wrong.

I've re-jigged the code as per your previous comment - at least I think I've done it as your previous comment 😉

When I add the code below, to the process I've written and load it as a custom menu item, everything works ok until the user cancels out of the dialog.

If the user cancels a dialog pops up saying 'An internal error occured.'

The debugger also pops up with the following:

        TypeError: fn is null
        1:Menu:Exec

 

Here's my new code...

var exitDialog = 0; 
while (exitDialog != 999)
    	{ 
    		var cRtn = app.response("How many checkboxes would you like (1-9) ?");
	    	if (cRtn == null) {
	    		break;
	    	}
    	    else if (cRtn < 1 || cRtn > 10)
   	    	    	{
   	    	    		app.alert('Please enter a value from 1-9');
    	    	    	}
    	    	else 
    	    	    	{
    		    		var exitDialog = 999;
    		    	}
    	}

Please can someone point me in the right direction?

 

Thank you 🙂 

Likes

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 ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

The error message is about something else. Post the full code, please.

Likes

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
Participant ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

Thanks for the reply.

 

Apologies, I came back from a lunch break and put a simple alert in the code.

With that in I could see that the execution of the code hadn't ended hence the error.

I thought 'break;' stopped everything.

I've now put in something in the code to stop the execution of the main process.

Thanks again for your time on this 🙂

Likes

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 ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

There is no "stop all further code" command in JS. The "break" command only stops a loop from continuing.

The other similar command is "return", which will exit a function immediately. But it won't work if used outside the context of a function.

Likes

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
Participant ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

Thanks for the quick response and for the explanation Gilad.

If I'd simply put an alert in, at the end of the code above, it would have indicated the execution hadn't ended.

Likes

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 ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

Correct. Well, you learn through experience!

Likes

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
Participant ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

LATEST

Absolutely!

Thanks again Gilad 🙂

Likes

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