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

After Submit It stops working? #88

Open anup36 opened 8 years ago

anup36 commented 8 years ago

Basically i have a Form on submit button am trying to check some conditions of form fields, When I hit the onsubmit button the Page first check all conditions and if any condition not match display error message but the Problem is after clicking onsubmit AreYouSure stops working and if i reload the page not display the Confirmation Box. But after some time later it's start's working properly?

codedance commented 8 years ago

Hi @anup36 . Are you able to provide an example page demonstrating the issue? e.g. a public URL test page, or codepen etc?

niketh90 commented 8 years ago

Create a page with submit button and a validation .Click submit button it will throw some validation .Enter a text field click close.It wont pop up warning.

sreed4 commented 8 years ago

I am seeing a similar thing with an ajax submit. Everything works great until a timer fires a JQuery ajax call that stores a working copy of the form. After the ajax call setting a changed back to its original value still leaves the form dirty. The code is: $(function() { MessageTimer = new $.timer(function() {ClearStatusMessage(2)}, 3000, false); DirtyTimer = new $.timer(SaveRecord, 10000, false); $('form').areYouSure(); $('form').bind('dirty.areYouSure', function() { $(this).find('input[type="submit"]').removeAttr('disabled'); SetStatusText("Needs to be saved.", 1); DirtyTimer.play(); }); $('form').bind('clean.areYouSure', function() { $(this).find('input[type="submit"]').attr('disabled', 'disabled'); ClearStatusMessage(2); ClearStatusMessage(1); DirtyTimer.stop(); MessageTimer.stop(); }); $('input[type="submit"]').attr('disabled', 'disabled'); }); function SaveRecord() { DirtyTimer.stop(); if (! $('#teamform').hasClass('dirty')) { return; } $("#type").val("tmp"); $("#action").val("Update"); var data = $('#teamform').serialize(); $.ajax( { data: data, url: "SaveTeam.php", cache: false }) .done(function(result) //successful ajax call { if(result.indexOf("Error") < 0) { SetStatusText("Temporary copy saved.", 2); } else { SetStatusText("Temporary copy failed.", 2); } }); // $("#teamform").trigger('reinitialize.areYouSure'); MessageTimer.play(); DirtyTimer.play(); }

tboby commented 8 years ago

I can confirm this issue using MVC 5's unobtrusive validation. If I had to hazard a guess I'd say it's just to do with the ordering of the submit handlers? I have no idea how you resolve that though.