Created
June 17, 2024 23:44
-
-
Save keenthemes/6c71fa8566bc0dcd1abaa8d44d522c0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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