From a516111b8284a05f2e126876ff38ff68636da766 Mon Sep 17 00:00:00 2001 From: Wesley Hampton Date: Thu, 16 Jul 2015 09:17:47 -0400 Subject: [PATCH 1/3] Update README.md Documented usage with a custom jQuery .submit() event handler. --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 0d925cb..c141046 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,21 @@ $(function() { } } + /* + * Usage with a custom jQuery .submit() event handler and validation + * Important to bind Are-you-sure to your form prior to binding your custom submit event handler + * This way you can have the form rechecked for dirtiness if your validation fails. + */ + // Initialize/Bind Are-you-sure to your form first + $('#myform').areYouSure(); + + // Custom submit event handler defined second + $('#myform').submit(function (event) { + if (validation_fails) { + $('#myform').trigger('checkform.areYouSure'); + event.preventDefault(); + } + }); } ``` The [demo page](http://www.papercut.com/products/free_software/are-you-sure/demo/are-you-sure-demo.html) @@ -208,6 +223,7 @@ known integration methods: * [Chosen jQuery Plugin](http://harvesthq.github.io/chosen/) - Integration discussed [here in issue #48](https://github.com/codedance/jquery.AreYouSure/issues/48) * [Redactor WYSIWYG html editor](http://imperavi.com/redactor) - Integration discussed [here in issue #17](https://github.com/codedance/jquery.AreYouSure/issues/17) +* [jQuery Submit Handler](http://api.jquery.com/submit/) - Integration discussed [here in issue #31](https://github.com/codedance/jquery.AreYouSure/issues/31). See Advanced Usage example above. ###Known Issues & Limitations From 34c6a26ee20c4f31c950f8ebe5f508fea0cccc6b Mon Sep 17 00:00:00 2001 From: Wesley Hampton Date: Thu, 16 Jul 2015 09:32:53 -0400 Subject: [PATCH 2/3] Update README.md Updated spacing and comments to match existing style. --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c141046..c44a82f 100644 --- a/README.md +++ b/README.md @@ -167,14 +167,17 @@ $(function() { */ // Initialize/Bind Are-you-sure to your form first $('#myform').areYouSure(); - // Custom submit event handler defined second $('#myform').submit(function (event) { if (validation_fails) { - $('#myform').trigger('checkform.areYouSure'); - event.preventDefault(); + // Force Are-you-sure to recheck the form since we're not leaving the page afterall + $('#myform').trigger('checkform.areYouSure'); + // ... Show message to user, log errors...etc + // Prevent form from completing the submit process + event.preventDefault(); } }); + } ``` The [demo page](http://www.papercut.com/products/free_software/are-you-sure/demo/are-you-sure-demo.html) From c22a8a7ce9d5f151dc080006b666c597ad85ea0d Mon Sep 17 00:00:00 2001 From: Wes Hampton Date: Tue, 13 Oct 2015 09:11:43 -0400 Subject: [PATCH 3/3] Additional var scoping Fixed console errors where these variables were not defined prior to use. --- jquery.are-you-sure.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jquery.are-you-sure.js b/jquery.are-you-sure.js index 3c41e2f..ea62da3 100644 --- a/jquery.are-you-sure.js +++ b/jquery.are-you-sure.js @@ -88,7 +88,7 @@ return; } - $fields = $form.find(settings.fieldSelector); + var $fields = $form.find(settings.fieldSelector); if (settings.addRemoveFieldsMarksDirty) { // Check if field count has changed @@ -102,7 +102,7 @@ // Brute force - check each field var isDirty = false; $fields.each(function() { - $field = $(this); + var $field = $(this); if (isFieldDirty($field)) { isDirty = true; return false; // break @@ -156,7 +156,7 @@ if (!settings.silent && !window.aysUnloadSet) { window.aysUnloadSet = true; $(window).bind('beforeunload', function() { - $dirtyForms = $("form").filter('.' + settings.dirtyClass); + var $dirtyForms = $("form").filter('.' + settings.dirtyClass); if ($dirtyForms.length == 0) { return; }