Skip to content

Instantly share code, notes, and snippets.

@theflowglenn
Created June 22, 2011 19:37
Show Gist options
  • Save theflowglenn/1040942 to your computer and use it in GitHub Desktop.
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
// 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); })
@theflowglenn
Copy link
Author

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;
}

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