Jamie Treworgy
Jamie Treworgy

Reputation: 24344

After preventing onClose with SimpleModal, default close control doesn't work

In a basic SimpleModal implementation, I use the onClose option to check for a dirty form state and prevent closing:

.. 
    function onModalClose() {
       if (this.dirty && 
             !confirm('You have unsaved changes, continue anyway?')) {
           return;
       } 
       this.dirty=false;
       $.modal.close();
    }
..

Problem is if the user cancels the close operation, the default Close control on the dialog no longer works. $.modal.close() still works.

I am sure I can get around this by not using the default button, or doing something like actively re-binding my own close function to it, but this seems strange, and I wonder if there is some easy solution I'm overlooking.

Upvotes: 3

Views: 1174

Answers (1)

Hugo
Hugo

Reputation: 10421

It's a bit of a hack but I had success with the following code. (Note: I defined the onClose function, so this points to the modal dialog.)

 onClose: function () {
     if (this.dirty &&
            !confirm('You have unsaved changes, continue anyway?')) {
         this.bindEvents();
         this.occb = false;
         return;
     }
     $.modal.close();
  }  

Upvotes: 4

Related Questions