javascript - Using Deferred to create custom Jquery UI Modal -
i trying recreate of functions of browser confirm box. need custom 1 our purpose.
my issue if statement on button click returns immediately, instead of after jqconfirm function has received user input , promise returned.
any ideas?
$('#testbutton').click(function () { if (gjs_confirm('this question, sure want to?????')) { alert('ok'); } else { alert('cancel'); } }); function gjs_confirm(msg) { $.when(jqconfirm(msg)) .then(function () { $("#dialog").dialog("close"); return true; }) .fail(function () { $("#dialog").dialog("close"); return false; }); } function jqconfirm(msg) { var deferred = $.deferred(); $("#dialog").dialog({ // autoopen: false, modal: true, resizable: false, height: 140, title: 'confirm', buttons: { ok: function (e) { deferred.resolve(); }, cancel: function (e) { deferred.reject(); } } }).text(msg); return deferred.promise(); }
html
<button id="testbutton" type="button"></button> <div id="dialog" title="basic dialog"> </div>