views:

521

answers:

3

Hello,

I have Create and Cancel buttons as part of a jquery-ui modal dialog. I want to do certain thing after closing the dialog only if the user clicks "Create". If they click "Cancel", or "X" or press Esc, I want to do something else. Is there a way to pass parameters to the close event handler or some other way to detect what caused the close?

+2  A: 

try this as discribed here: http://jqueryui.com/demos/dialog/#modal-confirmation

-- edit

copied from the link from above:

 var trigger = "";
 $("#dialog").dialog({
  bgiframe: true,
  resizable: false,
  height:140,
  modal: true,
  overlay: {
   backgroundColor: '#000',
   opacity: 0.5
  },
  buttons: {
   'Create': function() {
    // do your stuff
    trigger = "create";
    $(this).dialog('close');
   },
   Cancel: function() {
    $(this).dialog('close');
   }
  }
  close: function() {
   if (trigger == "create")
       // do something here
  }
 });
stefita
right, I'm wondering how I can detect inside the close handler what triggered it.
mh, on the top of my head- declare a var trigger = ""; as global and set it in the 'Create' function. Than you can get the value in the close handler...
stefita
doh! thanks man!
sorry i never marked this as answer! How rude of me!
no problem :)! thanks.
stefita
+1  A: 

define events for your buttons like this

$("#dialog").dialog({
  bgiframe: true,
  autoOpen: false,
  height: 300,
  modal: true,
  buttons: {
   'Create': function() {
    alert('the user clicked create');
    $(this).dialog('close');
   },
   Cancel: function() {
    alert('the user clicked cancel');
    $(this).dialog('close');
   }
  },
  close: function() {

  }

});

Also take a look at the parameters passed into the close event, the method signature is function(event, ui)

you can find more info here link text

sbeardsley
right, I'm wondering how I can detect inside the close handler what triggered it.
A: 
$('#jqPopup').dialog({modal:true,title:tit,autoOpen:false,beforeclose:function(){
   //Will get triggered when user press the 'X' button 
   $("#wholeContent").css('display','block');} 
});

$("#wholeContent").css('display','none');

$('#jqPopup').dialog('open');
ajai