Skip to content Skip to sidebar Skip to footer

Force Check Dirtyforms.js

I'm trying to check for dirty form when swithing between tabs - and if the form is dirty, show the alert. I'm using this plugin: https://github.com/snikch/jquery.dirtyforms Ii work

Solution 1:

In this case, you can customize the event binding to attach the click handler to your link.

$(document).bind('bind.dirtyforms', function (ev, events) {
    var originalBind = events.bind;

    events.bind = function (e) {
        $('#myTab li a').on('click', events.onAnchorClick);
        originalBind(e);
    };
});

Dirty Forms will then correctly

  1. Check whether the form is dirty
  2. If dirty, prevent the click event
  3. Show the dialog
  4. If the user decides to proceed, will refire the click event

Dirty Forms ignores your anchor tag by automatically because it has no HREF tag. This was a feature that was contributed by the community, that I am now reconsidering because apparently there is an argument to monitor anchor tags that don't have HREF sometimes.

Update

The default behavior has changed in 2.0.0-beta00005 to include links with no HREF tag by default. That should fix this so you don't need to attach the event. However, depending on what libraries you are using, you may need to add an ignoreSelector to Dirty Forms to stop watching them.

$('form').dirtyForms({ ignoreSelector: 'a.some-class:not([href])' });

Post a Comment for "Force Check Dirtyforms.js"