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 🙂
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.
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.
Copy link to clipboard
Copied
Thanks for the speedy response 🙂
I'll re-jig things as per your post.
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 🙂
Copy link to clipboard
Copied
The error message is about something else. Post the full code, please.
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 🙂
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.
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.
Copy link to clipboard
Copied
Correct. Well, you learn through experience!
Copy link to clipboard
Copied
Absolutely!
Thanks again Gilad 🙂