title: jQuery UI dialog: submitting a form with a dialog button
body: <p>In my web app, I have a list of editable objects, each with an "edit" link. Now, when you click the "edit" link, a jQuery UI dialog pops up, and the edit form for that object is displayed. On the bottom are "save" and "cancel" buttons. when "save" is clicked, the form is supposed to be submitted to the server. That's what I'm unable to do.</p>
  
  <p>Some particularities are that the edit form is loaded onto the dialog div via ajax when "edit" is clicked on one of the list items, so maybe it has something to do with that. Here are some code excerpts from the app. I'm working with Ruby on Rails 3.1.</p>
  
  <p>The view:</p>
  
  <pre><code>&lt;html&gt;
  ...
  &lt;body&gt;
      ...
      &lt;div id="edit-campaign"&gt;&lt;/div&gt;
      &lt;script&gt;
      $(function() {
      var buttons = { 
              "Save": function() { $("#edit-campaign-form").submit(); },
              "Cancel": function() { $("#edit-campaign").dialog("close"); }
                };
      createDynamicDialog("edit-campaign", buttons, "edit-campaign", "Edit Campaign");
      });
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The createDynamicDialog function (in another script file): This is the one where I make each "edit" link load their edit forms (URL in the href attribute) onto UI dialogs.</p>
  
  <pre><code>createDynamicDialog = function(divId, buttons, cls, title) {
      $("." + cls).click(function(e) {
          e.preventDefault();
          var dialogOptions = {   
                                  title: title,
                                  width: 800,
                                  height: 500,
                                  modal: true,
                                  autoOpen: true,
                                  buttons: buttons
                              };
          var link = $(this);
          $("#" + divId).load(link.attr('href')).dialog(dialogOptions);
      });
  }; 
  </code></pre>
  
  <p>With this, the "cancel" button works fine (closing the dialog), but the form isn't submitted when I click "save". Why could this be? I have a similar dialog that is loaded (the ajax part) when the page is loaded, and is only toggled through a button. That works fine. The problem is only when the loading of the form is done on the "click" event. Why?</p>
  
  <p>Thanks in advance for any help you can give me. I've been stuck on this forever...</p>