The solution: Prevent the user from being able to click the Save button or to when they do to ignore it.
$(document).ready(function() {
$("form").submit(function(e) {
if ($('form').valid()) {
$(':submit', this).each(function() {
if ($(this).attr('value') == 'Save') {
$(this).attr("disabled", "disabled").val("Saving....");
}
});
}
});
});
Couple of pointers:
- The button being pressed is of type submit
- The attr of the button gets disabled so the user cannot hit it again and again, and since the form is submitted there is no need for enabling it again.
- In this example I have also overridden the value of the button to indicate that the form is being saved
- In this example all submit buttons are impacted ($(':submit', this))
$(document).ready(function() {
$("#myButton").submit(function(e) {
$('#myButton', this).attr("disabled", "disabled").val("Processing....");
});
});
Oops, this does not work!!!!!!!!!!!!!!!!
The reason being is that the submit action is attached to the form not the "myButton". In order to perform the above and find out which button was pressed and take appropriate action do:
$("form").submit(function(e) {
if (e.originalEvent.explicitOriginalTarget.id == "myButton") {
//Do something
}
});
No comments:
Post a Comment