jquery-validation / jquery-validation

jQuery Validation Plugin library sources

Home Page:https://jqueryvalidation.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Validation error when remote check fields is preloaded.

AlterDevi opened this issue · comments

Your environment

  • Version of jquery-validate:
  • Browser name and version:

Current behavior

Suppose a form with 2 fields, vat and name of company
vat, name
vat field is remote validated, if vat is valid, remote script return true, else return false.

So we have the rules:
rules: {
vat: {
required: true,
remote: {
url: "ccif/",
type: "post",
data: {
vat: function() {
return $( "#vat" ).val();
}
}
}
},
name: {
required: true,
minlength: 2,
},
},
messages: {
vat: {
required: "CIF required.",
remote: "CIF invalid",
},
name: {
required: "Enter the name.",
minlength: "Name should contain at least 2 chars.",
},
},
...

When page is loaded and submit is pressed the both fields appear that need to be completed.
But if vat value is preloaded, both script show check sign green, even the name field show a red message.

Interesting behaviour is when press submit first field appear ok, second appear first in red which is correct but at miliseconds turn green which is not correct because fields is empty.

Expected behavior

What shoud be normal, is to check vat remotely and show the check sign green, if vat correct
and to show check sign red because field name is empy.

Live demo

you can check this on https://www.primulpas.ro/validator/

commented

I can't replicate this on JSFiddle - https://jsfiddle.net/bytestream/cjvrbpht/10/

You can replicate at your computer, this is not the issue.