Hi everyone,
I tried to set a validation that does not allows for 2 different Emails or Ids to register(like if that Email already registered). In order to check my code, used console.log(emailCount) to see how many are there in my DB. the code works. BUT i think i have a problem with the async function that i cant solve.
here is where i called my functions:
$w.onReady(function () { $w("#name").onCustomValidation((value, reject) => { if (value.length > 32 || value.length < 3) { reject("השם צריך להיות בין 3 - 32 תווים"); } }); $w("#email").onCustomValidation((value, reject) => { if (!checkEmail(value)) { reject("אמייל לא נכון או קיים במערכת");} }); $w("#ID").onCustomValidation((value, reject) => { if (!checkID(value)) { reject("תעודת זהות לא נכונה או קיימת במערכת"); } });
and here are the functions:
async function checkEmail(email) { let dataset = $w("#dataset1"); let emails = await wixData.query("Students").eq("email", email).count(); let end = email.endsWith(".com"); let dot = email.search(".") === email.length-3; return emails&&end&˙ } async function checkID(id) { let dataset = $w("#dataset1"); let ids = await wixData.query("Students").eq("id", id).count(); console.log(ids); return ids === 0; }
Thank you guys:)
Hi, yoav.
I could have missed it; what did you indicate was the problem WRT the async function? And which async function had the problem?