acvwilson / dirty_form

A jQuery plugin for alerting users to unsaved changes to forms before they leave a page or tab...
GNU General Public License v2.0
73 stars 7 forks source link

synthetic click() rather than use href attr? #2

Open dgoldenichec opened 14 years ago

dgoldenichec commented 14 years ago

I experimented with switching to synthesizing clicks rather than relying on href. This allowed me to dirty_stopper() elements that didn't or aren't supposed to have href attributes, such as form input submit buttons, not just a. It seemed to work, though n.b. the below doesn't address a bunch of cases (like clicking not actually ultimately navigating away...). The href approach might be more robust.


--- /usr/local/src/dirty_form/jquery.dirtyform.js       2009-09-09 12:10:52.000000000 +0100
+++ jquery.dirtyform.js 2010-02-03 12:55:05.000000000 +0000
@@ -173,19 +173,22 @@
           }
         })
       } else {
         stopper.unbind('click.dirty_form')
         stopper.bind('click.dirty_form', function(event){
           if($('.dirtyform').are_dirty()) {
             event.preventDefault();
             var div = $("
").appendTo(document.body), - href = $(this).attr('href'); + element = $(this); div.dialog($.extend({buttons: { - Proceed:function(){window.location = href}, + Proceed:function(){ + element.unbind('click.dirty_form'); // n.b. assumes proceeding navs away. + element.trigger('click'); + }, Cancel:function(){$(this).dialog('destroy').remove(); return false} } }, settings.dialog)).dialog("moveToTop").append(settings.message); } }); } }); }