Mirco
Mirco

Reputation: 189

JQuery-ui Dialog: How can I prevent default action when the user clicks on close button?

i'm using JQuery-ui dialog;

i'd like to perform my custom actions when user clicks on dialog's close button [X], but i'd like to prevent the closing event too!

i tried this code without success:

$( ".selector" ).dialog({
       close: function(event, ui) {
          event.preventDefault();
          //mycode              
          }
});

Even if i wrote the code above the dialog is closed bypassing my "preventDefault".

Thank you!

MV

Upvotes: 4

Views: 4420

Answers (2)

TimK
TimK

Reputation: 61

I've been looking for an answer to this too - so far the best I've come up with is

$( ".selector" ).dialog({
   beforeClose: function(event, ui) {
      //mycode              
      return false;
      }
});

Upvotes: 6

T.P.
T.P.

Reputation: 2995


$('.selector').bind('dialogbeforeclose', function(event,ui){
  alert('hello');
});

Upvotes: 1

Related Questions