Created
June 22, 2011 19:37
-
-
Save theflowglenn/1040942 to your computer and use it in GitHub Desktop.
Snippet from Rails 3 Client Side Validations JS to allow for AJAX spinner
This file contains 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
// Set up the events for the form | |
form | |
.submit(function() { return form.isValid(settings.validators); }) | |
// added loading toggle to handle the feedback spinner image (and changed 'beforeSend' to just 'before') | |
.bind('ajax:before', function() { $("#loading").toggle(); return form.isValid(settings.validators); }) | |
.bind('ajax:success', function() { $("#loading").toggle(); }) | |
// Callbacks | |
.bind('form:validate:after', function(eventData) { clientSideValidations.callbacks.form.after( form, eventData); }) | |
.bind('form:validate:before', function(eventData) { clientSideValidations.callbacks.form.before(form, eventData); }) | |
.bind('form:validate:fail', function(eventData) { clientSideValidations.callbacks.form.fail( form, eventData); }) | |
.bind('form:validate:pass', function(eventData) { clientSideValidations.callbacks.form.pass( form, eventData); }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and this is my CSS in case people want it:
loading {
width: 16px;
height: 16px;
margin-left: 10px;
margin-right: 10px;
background: url('../images/ajax-spinner.gif');
display: none;
}