Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You want to change the configuration of the dialog on click (in this case, the behaviour of the Ok button). For that your have many solutions all of them ugly (imo). I would advice generating a dialog on the fly, and destroying it once it has been used, something like this:</p> <pre><code>$("#delete").click(function(ev) { ev.preventDefault(); // preventDefault should suffice, no return false var href = $(this).attr("href"); var dialog = $("&lt;div&gt;Are you sure?&lt;/div&gt;"); $(dialog).dialog({ resizable: false, autoOpen: true, modal: true, buttons: { 'OK': function() { window.location = href; $( this ).dialog( "close" ); }, 'Cancel': function() { $( this ).dialog( "close" ); } }, close: { $( this ).remove(); } }); }); </code></pre> <p>Or even better, encapsulate the confirm dialog into a function so that you can reuse it, like so:</p> <pre><code>function confirmDialog(msg) { var dialog = $("&lt;div&gt;"+msg+"&lt;/div&gt;"); var def = $.Deferred(); $(dialog).dialog({ resizable: false, autoOpen: true, modal: true, buttons: { 'OK': function() { def.resolve(); $( this ).dialog( "close" ); }, 'Cancel': function() { def.reject(); $( this ).dialog( "close" ); } }, close: { $( this ).remove(); } }); return def.promise(); } </code></pre> <p>And then use it like so</p> <pre><code>confirmDialog("are your sure?").done(function() { window.location = $(this).attr("href"); }).fail(function() { // cry a little }); </code></pre> <p>You may have to check if the deferred object has been rejected or resolved before you close the dialog, to ensure the confirm rejects on close (and not just on pressing the 'Cancel' button). This can be done with a def.state() === "pending" conditional.</p> <p>For more information on jquery deferred: <a href="http://api.jquery.com/category/deferred-object/" rel="noreferrer">http://api.jquery.com/category/deferred-object/</a> </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload