Hi there,
this is the code I use to prevent any double entry in my contest form, the problem is that it works in the Editor Preview mode and not in the live site…
I did sync the database from Live to SandBox, then SandBox to Live many times but still the same issue…
Contest form page:
$w.onReady(function () {
$w("#submitDataset").onAfterSave(() => {
// after the save is completed on the submitDataset,
// refresh the displayDataset which will refresh the connected repeater
$w('#displayDataset').refresh();
});
});
Backend - Data.js
import wixData from 'wix-data';
export function searchForDuplicates(value, info) {
// info contains the hook context
// use the collectionName property to use function for multiple collections
return wixData.query("Lead_Collections_DB")
.eq("email", value.email)
.find()
.then((results) => {
return results.items.length;
})
.catch((err) => {
let errorMsg = err;
});
}
export function Lead_Collections_DB_beforeInsert(item, context) {
// Calls routine to check if value already exists in the collection.
// If value not found, then save record.
// Else, if value is found, then reject this insert to prevent duplicate values.
// Note: concurrent inserts may result in duplicates.
// Pass context to searchForDuplicates to use for multiple collections.
return searchForDuplicates(item, context).then((res) => {
if(res > 0) {
return Promise.reject('This item already exists');
}
return item;
});
}
Duplicate successful block in Preview mode:
Duplicate fail block in Live mode:
So what did I did wrong here, please?
Thanks
Yassine