Reputation: 7892
How do you prevent double clicks on MVC Html.SubmitButton using jQuery, it also need to take into consideration the validation controls on the form.
Can someone show a code sample
Upvotes: 2
Views: 2643
Reputation: 3569
Something like:
$('#yourButtonId').click(function() {
// Check validation before disabling
if ($(this.form).valid()) {
this.disabled = 'disabled';
}
});
Note that this will work for MVC3 unobtrusive validation, not sure if that's what you're using.
Upvotes: 6
Reputation: 24729
Here is what I use.You can get more specific with the selector As this script is used on a very simple page.
$(document).ready(function ()
{
$('#butSubmit', this).removeAttr("disabled", "disabled");
});
$('form').submit(function ()
{
if ($(this).valid())
{
$('#butSubmit', this).attr('disabled', 'disabled');
}
});
Upvotes: 5
Reputation: 3789
Put a javascript function on the button, and disable the button or hide it.
Upvotes: 1