Jack Thor
Jack Thor

Reputation: 1594

remote validation triggering multiple times

I am learning how to use C# remote validation. The problem that I have is that the the validation call is happening multiple times and the form is no longer submitting. When I comment out the remote validation attribute it works fine, or if the field is empty it works fine (fine as in the form gets submitted). Here is how I am defining the Remote attribute.

[DisplayName("User Type (Logged In)")]
[UIHint("DropDownList")]
[Remote("UserTypeCheck", "Settings", AdditionalFields = "Id,Context,Key")]
public List<int> UserTypeIds { get; set; } 

Inspecting the the DOM I see that the data-val-remote-url is being set correctly

enter image description here

But when I click the submit and look at the DEV console I can see that it is making three calls and that the second is aborting/canceling. I am not sure what is causing this. It is also not submitting the form even thought the event is firing since I added this handler to the submit event of the form

$form.submit(function() {
    console.log("submit got fired");
    console.log(this);
 });

the postback

enter image description here

Upvotes: 1

Views: 317

Answers (1)

Jack Thor
Jack Thor

Reputation: 1594

Turns out I was leaving out a missing piece of information. The remote validation from client side to server is done by the jquery.validate.js. With that said, jquery.validate was using an asynchronous call which did not finish in time before we tried submitting again, which causes it to re-validate the field. By setting async:false when defining the remote rule I was able to stop subsequent submit. I got the idea from mlynch comments here

Upvotes: 2

Related Questions