Skip to content

Instantly share code, notes, and snippets.

@bcardarella
Forked from theflowglenn/gist:1040942
Created June 22, 2011 19:43
Show Gist options
  • Save bcardarella/1040967 to your computer and use it in GitHub Desktop.
Save bcardarella/1040967 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); })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment