Hello, and for 6 days I’m beating my head on this field imput validation, but it keeps giving me the same mistakes even changing the method to get to the conclusion.
This is what I want to do:
- the field must contain 12 characters.
- if it contains 12 characters, check that a field called ImpuUser has spouses
- if both conditions are checked check in the database that there is no equal value.
this is the code
$w(“#inputCartella”).onCustomValidation((value, reject) => {
$w(“#dataset1”).onReady( () => {
if ( (value.length !== 12) && (value.length > 0) ) {
$w(“#error03”).text = “error lenght”;
$w(“#error03”).show();
reject(“error lenght”);
} else {
if (value ===“”) {
$w(“#error03”).hide();
} else {
if ($w(“#ImpuUser”).value === ‘Sposi’) {
wixData.query(‘RedirectCerimonie’)
.eq(‘db_cartella’, value)
.find()
.then(results => {
let resultCount = results.totalCount;
if ((resultCount !== 0) && ( $w(‘#SaveData’).label !== ‘Aggiorna’)) {
$w(“#error03”).text = “Cartella Esistente”;
$w(“#error03”).show();
reject(‘Codice Già Usato’); //does not work the input field remains valid
} else {
$w(“#error03”).hide();
}
});
} else {
$w(“#error03”).hide();
}
}
}
});
});
I thought it was a problem synchronous for the query made so I realized this but the problem is the same.
$w("#inputCartella").onCustomValidation((value, reject) => {
$w("#dataset1").onReady( () => {
if ($w("#ImpuUser").value === 'Sposi') {
wixData.query('RedirectCerimonie')
.eq('db_cartella', value)
.find()
.then(results => {
let resultCount = results.totalCount;
if ((resultCount !== 0) && ( $w('#SaveData').label !== 'Aggiorna')) {
$w("#error03").text = "Cartella Esistente";
$w("#error03").show();
reject('Codice Già Usato'); //does not work the input field remains valid
} else {
if ( (value.length !== 12) && (value.length > 0) ) {
$w("#error03").text = "Lunghezza Nome Cartella 12 Caratteri. Controlla il campo inserito";
$w("#error03").show();
reject("Lunghezza Nome Cartella 12 Caratteri. Controlla il campo inserito");//does not work the input field remains valid
} else {
if (value ==="") {
$w("#error03").hide();
} else {
$w("#error03").hide();
}
}
}
});
}
});
});
I state that both codes are in onready page
how can I solve, someone helps me
Tahnk you