Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ $(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) {
// 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)
Expand Down Expand Up @@ -208,6 +226,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

Expand Down
6 changes: 3 additions & 3 deletions jquery.are-you-sure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down