Skip to content

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

Description

@dgoldenichec

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions