Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created October 24, 2011 04:51
Show Gist options
  • Save pamelafox/1308396 to your computer and use it in GitHub Desktop.
Save pamelafox/1308396 to your computer and use it in GitHub Desktop.
Changing button states (Bootstrap)
<button class="btn save-button primary" type="submit" data-startmsg="Save" data-loadingmsg="Saving..." data-successmsg="Saved!">Save</button>
function setupFormSave(target, form, callback) {
var button = form.find('button[type="submit"]');
button.click(function(event) {
event.preventDefault();
button.html(button.attr('data-loadingmsg'));
button.attr('disabled', true);
sendForm(target, form, handleResponse);
});
function handleResponse(data) {
if (data.status == 'success') {
button.html(button.attr('data-successmsg'));
} else {
button.html(button.attr('data-startmsg'));
button.attr('disabled', false);
renderErrors(data.errors);
}
}
}
@neuropass
Copy link

how do you use this? thx should the script replace a code in button.js or it can be implemented separately?

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