Permalink
Browse files

Unset data-dirty on form submit, to prevent onbeforeunload.

  • Loading branch information...
1 parent b7775ff commit ddf60992b60b235961cfac06c6611e5aa6f6bc25 @jpic jpic committed Feb 19, 2013
Showing with 8 additions and 1 deletion.
  1. +8 −1 session_security/static/session_security/script.js
@@ -37,6 +37,7 @@ yourlabs.SessionSecurity = function(options) {
if (this.confirmFormDiscard) {
window.onbeforeunload = $.proxy(this.onbeforeunload, this);
$(document).on('change', ':input', $.proxy(this.formChange, this));
+ $(document).on('submit', 'form', $.proxy(this.formSubmit, this));
}
}
@@ -128,5 +129,11 @@ yourlabs.SessionSecurity.prototype = {
// When an input change, set data-dirty attribute on its form.
formChange: function(e) {
$(e.target).closest('form').attr('data-dirty', true);
- }
+ },
+
+ // When a form is submited, unset data-dirty attribute.
+ formSubmit: function(e) {
+ console.log($(e.target))
+ $(e.target).removeAttr('data-dirty');
+ },
}

0 comments on commit ddf6099

Please sign in to comment.