Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File dialogs cancel event #292

Closed
rumax opened this issue Dec 24, 2012 · 4 comments
Closed

File dialogs cancel event #292

rumax opened this issue Dec 24, 2012 · 4 comments

Comments

@rumax
Copy link

rumax commented Dec 24, 2012

Is there a way to detect "Cancel" button event in file dialog?

var chooserEntered = function() {
//do some staff. Ok
};
var chooserCanceled = function() {
//do some staff. How to call???
}

var chooser = $('');
chooser.change(function(e) {
console.log(chooser.val());
chooserEntered(chooser.val());
});
chooser.click();

@rumax
Copy link
Author

rumax commented Dec 24, 2012

One more issue:

  • Focus is lost from currently active element (document.activeElement is set to body after fileDialog closed)

@kochelmonster
Copy link

This is a hack but works:
before opening the dialog, you have to change the input's value like
$("#file-dialog")[0].files.append(new File("", ""))
When the user cancels the dialog, $("#file-dialog").val() is empty

@sompylasar
Copy link

The hack proposed by @kochelmonster causes nwjs 0.12.1 to crash under Mac OS X 10.9.2.
I've managed to find another one – handle the nwjs Window focus event. Please see here: sompylasar/node-webkit-fdialogs@fb7a606#diff-025b14d5d2e91d029d15c4e4a0dbbcb8R100

@victoroliveira
Copy link

Another approach is to add a cancel event listener:

$('#fileDialog')).addEventListener('cancel', (evt) => {
  console.log('DISMISS DIALOG');
  const path = (evt.target as HTMLInputElement).value;
  console.log(`Path: ${path}`);
}, false);

This works for me, and variable path is empty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants