I am disabling my submit buttons when submitting a form, for preventing the user to submit the form multiple times.
$(function ()
{
$("form").submit(function ()
{
$(":submit", this).attr("disabled", "disabled");
});
});
But if the client validation fails I want to enable the button again. I am using asp.net mvc unobtrusive client validation
Firstly, you just need to create an ASP.NET MVC application. To create a new ASP.NET MVC application, Open Visual Studio choose File, New, then Project. It will open a New Project window, from where you need to choose node Visual C# and then Web and from the right pane you need to choose ASP.NET Web Application.
It turns out that to enable client side validation without using the HtmlHelpers and a model you just have to add an input with data-val="true" and then data-val- followed by validation method that you want to apply (e.g. data-val-required ), the value of which will be the error message presented to the user (e.g. data ...
ModelState. IsValid indicates if it was possible to bind the incoming values from the request to the model correctly and whether any explicitly specified validation rules were broken during the model binding process. In your example, the model that is being bound is of class type Encaissement .
You can use the jQuery One event as detailed in this answer.
Most solutions to this issue revolve around testing $("form").valid() - you could probably use this in your function to determine whether to disable the submit button.
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