Have mercy! What am I missing? I am trying to use onCustomValidation on a text input that receives an email. I want to check if the email exists already and if not, I’m creating a id for the user to save when the rest of the form is submitted.
onCustomValidation is running when the page is loaded, which I’m not sure why. The input is required, maybe that’s part of the problem?
Also my If statement within onCustomValidation is not working - it still seems to be running the code even if the condition is not met.
I’m all turned around at this point.
$w.onReady(function () {
$w("#txtEmail").onCustomValidation( (value, reject) => {
console.log(typeof(value));
if(!value || value !== "" || value !== undefined)
{
verifyEmail(value)
.then((thisResult) => {
if(thisResult === false)
{
$w('#txtEmailError').text = "Must have valid email in order to submit.";
}
else
{
reject('Email is already in use');
$w('#txtEmailError').text = $w("#txtEmail").validationMessage;
}
});
}
});
});
export async function verifyEmail(value) {
await wixData.query("Contractors")
.eq("contractorEmail", value)
.find()
.then( (result) => {
if(result.totalCount === 0)
{
$w('#contractData').onReady(()=> {
genContractId()
.then((txtValue) =>{
$w('#contractData').setFieldValue("contractorId", txtValue);
});
});
return true;
}
else
{
return false;
}
});
}