Canceling getFileForOpening dialog

Hello.

When I cancel my getFileForOpening dialog (by either hitting Cancel or escape) the execution of my plugin stops and the assigned result variable doesn’t exist at all. Any idea why that happens? Here’s the code that I use.

document.getElementById(“button_getfile”).addEventListener(“click”, async evt => {
const filename = await fs.getFileForOpening();
if(!filename) {console.log(“Cancel”);}
});

The console won’t show anything at all.

Your code is correct. I tried it and did not have a problem with cancelling the dialog.

1 Like

I can cancel the dialog, but the “if”-condition doesn’t get triggered. I’ll try again tomorrow.

I’ve tried the code again and it doesn’t trigger the console output. When I put the getFileForOpening call into a “try” block, the error condition as well as the “Cancel” output are triggered. So it seems as if canceling the Open File dialog triggers an error.

document.getElementById(“button_getfile”).addEventListener(“click”, async evt => {
try{
var filename = await fs.getFileForOpening();
} catch {console.log(“Error”);}
if(!filename) {console.log(“Cancel”);}
});

And “const filename …” doesn’t work for the “if” condition afterwards, the “var filename …” version does.

Also … “sp-button” and “sp-action-button” don’t seem to work properly with the dialog either. When I trigger them, after canceling the dialog, another dialog pops up (but can’t be accessed - it’s just open in the background). A normal HTML button seems to work.

I am not able to reproduce any problem using this code or with other plugins. It is difficult to say what might be wrong. Can you see if you still experience the problem when using this sample plugin?

I’m using Photoshop, so I don’t thing that I can use this plugin. At least I can’t load it in UXP Developer.

The Photoshop forum might be able to help:

1 Like

Yeah - I found that out in the meanwhile. Cheers.