Chien Tran
Chien Tran

Reputation: 133

Javascript not wait file dialog closing

My problem is javascript not wait for file selection dialog closing. I have just found an solution that we declare a onChange event for element. So onChange event work right, but script still run before onChange event. They a asynchronous. I think may be there is a way to check if there is any dialog opening ? Please help me, 2 day of mine :)

Upvotes: 1

Views: 366

Answers (1)

Altis S.
Altis S.

Reputation: 21

If you want to call back method after dialog is completely opened, you can use using jQuery Promise object as mentioned in this answer:

$("#dialog").dialog({
    show: {
        effect: "drop",
        direction: "up",
        duration: 1000
    },
    hide: {
        effect: "drop",
        direction: "down",
        duration: 1000
    },
    open: function () {
        $(this).parent().promise().done(function () {
            console.log("[#Dialog] Opened");
        });
    },
    close: function () {
        $(this).parent().promise().done(function () {
            console.log("[#Dialog] Closed");
        });
    }
});

Here is the usual JSFiddle Demo: http://jsfiddle.net/losnir/jcmpm/

Upvotes: 2

Related Questions