JQuery dialog won't open 2nd time

I found this thread , which basically has the same problem as mine. But their solution doesn't work for me.

The dialog appears the first time the submit button is pressed, but not the second time. I open the dialog after submitting the form.

UPDATE

Finally I started working. Here's 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 am dynamically applying the css class, I must make sure to add it to the outer DIV that creates the $ .dialog to wrap my DIV dialog.

+1


source to share


3 answers


Do not use dialog()

to initialize a dialog box and open it at the same time. I made this mistake too.

Initialize the dialog first, then open it in a callback like this:



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");
};

      

+1


source


I think the very much voted answer by RayLehman in the post you link to is the correct solution.

The jQuery UI dialog () function actually creates a dialog from some content. You don't actually call "open" in dialogue anywhere.



Once the dialog is created by calling dialog () the first time, you simply need to invoke the dialog ("open") or the dialog ("close"), rather than re-creating the actual dialog object each time.

+4


source


It looks like you completed the public event with init call. You need to make sure that you initialize your dialog first, usually setting the autoOpen property to false - and then you can open a separate click event for an individual dialog.

Read this article to explain it in detail.

0


source







All Articles