im using jquery with asp.net mvc. Im doing something like this so that the submit button becomes disabled when clicked.
but if there are validation errors i dont want it to be disabled.
$('form').submit(function () {
if ($('form').valid()) {
$('input[type=submit]', this).attr('disabled', 'disabled');
}
});
this makes it disabled, but even if there are validation errors. whats wrong?
EDIT: i'll try again after my first screw up :P
$('form').submit(function () {
if ($('form').valid()) {
$('input[type=submit]', this).attr('disabled', 'disabled');
}
});
Maybe there are other forms on the page, and it's validating the wrong one?
$('form').submit(function () {
if ($(this).valid()) {
$(this).find('input[type=submit]').attr('disabled', 'disabled');
}
});
oh and did you $('form').validate() to enable validation (which I would guess is called automatically by MVC if you're using MVC's validation, but I'm not 100% sure about that)?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With