Last active
December 20, 2015 19:09
-
-
Save jmarnold/6181561 to your computer and use it in GitHub Desktop.
New hooks for Matt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#myForm').on('validation:started', function() { | |
// you could have remote rules so you'll want to disable the button while you wait | |
$(this).find(':submit').prop('disabled', true); | |
}); | |
// This happens AFTER the promise has been completed and the notification has been resolved | |
$('#myForm').on('validation:onsubmission', function(e, validation) { | |
// Gives you access to the notification before the submission handler returns | |
// You could technically register additional messages here | |
//validation.notification | |
// Just flat out prevent submission | |
validation.preventSubmission(); | |
}); | |
// A note: | |
// The submission handler logic does: | |
// Submit the form if both of the following are true: | |
// 1. preventSubmission() was not explicitly called | |
// 2. notification.isValid() is true | |
// For successful responses | |
// Explicit | |
$('#myForm').on('validation:success', function(e, continuation) { | |
// whatever you need | |
}); | |
// conventional | |
var myPolicy = { | |
matches: function(continuation) { | |
return continuation.success && continuation.form; | |
}, | |
execute: function(continuation) { | |
// continuation.form is the actual jquery element | |
} | |
}; | |
// You could also hook into the rendering pipeline and do this as a rendering strategy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick note: 'validation:started' should be 'validation:start'