-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Need to capture cancel event in nwsaveas #4501
Comments
maybe relate with this issue #3596 |
I just ran into this same problem recently and figured a workaround. When the save/save-as dialog closes the window gets a focus event. So, instead of using the onchange event on the input control, I now use The tricky part is not knowing which event will be captured first, 'focus' on the Window or 'change' on the input, and if you check the control value too soon it will still be empty even if cancel was not used. So I use a small setTimeout to allow for the field to be updated (100 ms seems to be sufficient). Then, I just pull the .value of the input element and if it's empty, the dialog must've been cancelled (have to make sure to clear the input .value before invoking the dialog). This technique is working with nw.js 0.12.3 on Windows and OSX. |
This is fixed in git and will be available in the next nightly build. Additional "oncancel" event listener is now supported for this. |
I was using the workaround similar to @TrevorPT and #292 (comment). @rogerwang I've tried the |
Could someone provide a small sample script on how cancel event works? I haven't been able to make it work.
The message in console doesn't appear. |
I have followed the instructions for a SaveAs dialog and it works like a charms
EXCEPT...
If the user cancels, I have some code that needs to execute. However the cancel event doesn't trigger the change event.
So How can I respond to the cancel of the file saveas dialog?
function openSaveAs(prompt, cb) {
var saver = $('#saveAsFileDialog');
saver.attr('nwsaveas', prompt);
saver.unbind('change');
saver.val("");
saver.bind('change', function (evt) {
if(cb) cb($(this).val());
});
saver.trigger('click');
}
The text was updated successfully, but these errors were encountered: