codedance / jquery.AreYouSure

A light-weight jQuery "dirty forms" Plugin - it monitors html forms and alerts users to unsaved changes if they attempt to close the browser or navigate away from the page. (Are you sure?)
508 stars 145 forks source link

How to disable plugin on form submit? #109

Open tanraya opened 8 years ago

tanraya commented 8 years ago

Hello! I want to see the warning message only when I close the window or leave page, but not on the form submit.

So how can I disable the warning message on form submit?

hasangursoy commented 8 years ago

There is already a code for this purpose inside the plugin. But if you use ajax for submit, you need to remove dirty class from the form(s) or you need to unbind beforeunload handler.

$form.submit(function() {
    $form.removeClass(settings.dirtyClass);
});
westonganger commented 5 years ago

This issue is actually because you are replacing the form element in your code, jquery are you sure still thinks its tracking the form but the assigned events are lost.

This bug seems to crop up after validation errors or such. You must add code similar to the following to fix this issue.

$(document).ajaxComplete(function(){

  $("form").submit(function(){
    $(this).removeClass('dirty');
  });

});

We should find a way to integrate this code into the library so users dont have to do this themselves.