Skip to content

Instantly share code, notes, and snippets.

@jmarnold
Last active December 20, 2015 19:09
Show Gist options
  • Save jmarnold/6181561 to your computer and use it in GitHub Desktop.
Save jmarnold/6181561 to your computer and use it in GitHub Desktop.
New hooks for Matt
$('#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
@ventaur
Copy link

ventaur commented Aug 16, 2013

Quick note: 'validation:started' should be 'validation:start'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment