Code works in preview but if i publish it dosn't works

Hello everyone! I’m Veronica, its my first question, sorry.

i put this code in my custom registration form. This works in preview but if i publish it dosn’t works!

export function button2_click(event) {

console.log ('log : ’ + $w(“#input5”).value)
wixData.query(“Anag”)
.eq(“title”, $w(“#input5”).value)
.find()
.then(results => {
let resultCount = results.totalCount;
$w(“#input5”).onCustomValidation( (value, reject) => {
if( resultCount == 0 ) {
reject(“Codice Fiscale non valido”);
$w(“#input5”).validity.valid = false;
$w(“#input5”).updateValidityIndication();
}
})
})
.catch( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
}

so I have no idea what causes it, any ideas? Where i fault?
thank you

  1. Check the collection permissions.

  2. Make sure the collection in synchronized and that the data exist on the live collection.