The jQuery dialog box does not open the second time

advertisements

I found this thread which basically has the same issue I have. But their solution is not working for me.

The dialog appears the first time I click the submit button, but not the 2nd time. I'm opening the dialog box after a form submission.

UPDATE

I finally got it working. Here is the correct code:

   if (jQuery('#registrationforms').length > 0) {
     //instantiate the dialog
     jQuery("#dialog").dialog({ modal:true, autoOpen:false });

     //Some more code here to call processRegistration function.
   }

  function processRegistration(instanceID, formData)
  {

    jQuery.post("mypath/jquery_bll.php", { instance: 'processRegistration', formData : formData, instanceID : instanceID },
      function(feedback)
      {
        jQuery('#dialog').text(feedback.message);
        jQuery('#dialog').parent().addClass(feedback.type);
        jQuery('#dialog').dialog('open');
      },"json");

  }

Since I'm dynamically applying css class, I have to make sure to add it to the outer DIV which $.dialog creates to wrap my 'dialog' DIV.


Don't use dialog() to both initialize the dialog and open it at the same time. I made this mistake too.

First initialize the dialog, then open it in the callback like so:

jQuery('#dialog').dialog({ autoOpen: false });

function processRegistration(instanceID, formData) {
jQuery.post(...,
  function(feedback) {
    var dialog = jQuery('#dialog');
    dialog.text(feedback.message);
    dialog.addClass(feedback.type);
    dialog.dialog('open');
  }, "json");
};