Skip to content

Instantly share code, notes, and snippets.

@keenthemes
Created June 17, 2024 23:44
Show Gist options
  • Save keenthemes/6c71fa8566bc0dcd1abaa8d44d522c0e to your computer and use it in GitHub Desktop.
Save keenthemes/6c71fa8566bc0dcd1abaa8d44d522c0e to your computer and use it in GitHub Desktop.
const existClient = function () {
return {
validate: function (input) {
return new Promise((resolve, reject) => {
const value = input.value;
if (value === "") {
resolve({ valid: true });
} else if (value.length > 0) {
$.ajax({
url: "/clientes/findClient",
type: "GET",
data: { "id": value },
success: function (data) {
resolve({ valid: data.length === 0 });
},
error: function () {
resolve({ valid: true }); // or reject based on how you want to handle errors
}
});
} else {
resolve({ valid: true });
}
});
},
};
};
// Register the validator as usual
validator.registerValidator('existClient', existClient);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment