title: Remove beforeClose event handler - jQuery UI Dialog
body: <p>I have a jQuery UI dialog box with a form inside it. I'm trying to implement a feature where if a field in the form has been modified, we'll be showing a confirmation message using <a href="http://ned.im/noty/" rel="nofollow">noty</a></p>
  
  <p>Now, unlike an javaScript confirmation box, noty does not stop script execution. So, in the dialog <code>beforeClose</code> event, I'm -</p>
  
  <p>Showing a noty confirmation if form data <strong>is modified</strong> and then returning false.
  Simply returning true if the form data <strong>has not been modified</strong>.</p>
  
  <p>All is working well. Now we ask the user -</p>
  
  <p>The data in the form has been modified. Are you sure you want to close?</p>
  
  <p>If he clicks <strong>no</strong> - we simply close the noty and keep the dialog box open.
  But if he clicks <strong>yes</strong>, we try to close the dialog box, which triggers the <code>beforeClose</code> event handler again and we go into the loop again.</p>
  
  <p>I've tried calling <code>.off</code> on the <code>div</code> that has been converted to a dialog box before calling the close event, but that doesn't seem to be removing the click.</p>
  
  <p>Here is a simple pseudo code to explain the issue -</p>
  
  <pre><code>DialogCloseEvent() {
      if data has been modified { 
          Show noty {
              // IMPORTANT - This is executed after return false.
              in noty user clicks NO - do not close dialog box {
                  close noty and done
              } 
              in noty user clicks YES - close the dialog box {
                  // This calls the DialogCloseEvent again.   
                  call the close method of the dialog box.            
                  close noty
              }
          }
          return false
      }   
      no it has not been modifed {
          // Closes the dialog without calling the event again
          return true;
      }
  }
  </code></pre>