Skip to content

Instantly share code, notes, and snippets.

@tommaitland
Last active July 30, 2017 01:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommaitland/9904540 to your computer and use it in GitHub Desktop.
Save tommaitland/9904540 to your computer and use it in GitHub Desktop.
Code to provide callbacks and override how NationBuilder processes signups through AJAX
$(formSelector).submit( function(event) {
// Store the original NB function in a temp variable
var tmp = window.NB.EventHub.dispatch;
/**
* $(this) / $form is the entire signup form. onsubmit changes can be made by finding inputs/children
*
* ie. $form.find('input[type="submit"]').val('Loading');
*
**/
$form = $(this);
// Override the NB function
window.NB.EventHub.dispatch = function(e) {
if (e == 'form.success') {
// success
} else {
// error
}
// Restore the original NB function so things keep working
window.NB.EventHub.dispatch = tmp;
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment