1
I am validating some fields of an application form that was made in Ruby on Rails. In this application has some query endpoint, where it returns a json, if the CPF exists it returns this data:
{
"existe": true,
"user": {
"name": "Operador 2",
"cpf": "606.304.220-29"
}
}
And if it doesn’t exist it returns
{
"existe":false
}
The URL to query the CPF is the following way: http://localhost:3000/api/findUserByCpf? Cpf=606.304.220-28
And the js code of Jquery Validation, he’s returning the message on the console, but doesn’t help the countryside, making the field valid or invalid.
$(".validationNomeOperador").validate({
rules: {
'cpf': {
required: true,
cpf: true,
remote: {
url: "/api/findUserByCpf",
type: "GET",
data: {
cpf: function() {
return $("#validationCpfOperador").val()
}
},
dataType: 'json',
success: function(data) {
if (data.existe == true) {
console.log("Já existe o CPF cadastrado")
} else {
console.log("CPF disponivel")
}
}
}
},
},
messages: {
'cpf': {
required: "Informe o CPF",
remote: 'CPF já cadastrado'
},
}
});
your keys are very strange ... the true return is the same way?
– novic
@Virgilionovic was right, I just edited
– Sérgio Machado