I need to avoid the double click submitting behavior. I\'m using the client validation with the unobtrusive library. I have the following code for avoiding the double clic:<
I have a form that uses MVC3 unobtrusive validation, and a viewmodel with a [RemoteAttribute]. It looks to me like the form's submit event only fires after all validation has passed. I'm currently using this, and it seems to work:
$('form').live('submit', function() {
$(this).find('input[type="submit"][data-app-disable-on-submit="true"]')
.attr('disabled', 'disabled');
})
;
I set breakpoints on both the remote attribute validation action method and the HttpPost action method. Clicking the submit button the first time hits the breakpoint on the validation action method. At this point, the button is still enabled. I can click it multiple times, and after resuming the validation method, the HttpPost is hit only once. When the HttpPost is hit, the submit button is disabled.
Update
Right you are Alex. So an updated version of the above would look like this:
$('form').on('submit', function() {
$(this).find('input[type="submit"][data-app-disable-on-submit="true"]')
.attr('disabled', 'disabled');
})