I have just started learning JQuery validate and have come across an issue (no doubt it is of my own making) when I am trying to use the remote function.
The call to my action works and is hitting my API and returning the value I am expecting, I have also tested the output of the call in console.log()
so I am happy that the call is being made and returning values.
The validation message is not appearing when the return value is true. True being that UniqueMappingRef
exists, hence the error message saying such.
I have seen an answer, but this only seems to allow one remote function, when I will need an additional four to the one already in this question:
Currently no message appears at all.
The code is in the rules section and is called UniqueMappingRef
.
$("#ProjectPrepForm").validate({
onkeyup: false,
rules: {
ProjectName: {
required: true
},
UniqueMappingRef: {
required: true,
remote: {
type: "POST",
url: "/ProjectPrep/CheckUniqueMappingRef/",
data: {
'internalRef': function () {
return $('#UniqueMappingRef').val()
}
},
success: function (d) {
if (d == true) {
messages:{
UniqueMappingRef: 'It already exists.'
}
}
},
error: function (request, status, errorThrown) {
alert(status);
}
}
}
},
messages: {
ProjectName: {
required: 'Enter an project name'
},
UniqueMappingRef: {
required: 'Enter a unique mapping reference'
}
}
});
});
Issue: Validation message is not being show for remote call, even though the API is returning the correct value.
Expected outcome: when true, validation message is shown, false the message disappears. Once I understand what I have done wrong, I will add a further four call for different elements.