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
I have abandoned this road not knowing how to get out of it. I put unresolved
Hi Ido,
Thank you for your answer. I tried to insert return and as per your example but unfortunately the problem remains, the reject does not work. I see the error message and even with the log file everything works, but the box if it finds if it contains an error is not reported.
If you have other solutions to understand if this is a bug or not, because I understand if I change the approach to the problem.
Thank you
Hi,
Try adding a return before the wixData call:
$w("#inputCartella").onCustomValidation((value, reject) => {
$w("#dataset1").onReady( () => {
if ($w("#ImpuUser").value === 'Sposi') {
return wixData.query('RedirectCerimonie') //here
.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();
}
}
}
});
}
});
});
Hi Ido,
thanks for your answer.
I checked with all the possible ways, and I think it's a BUG of reject. In fact, even if the query is verified, the reject does not work.
I hope some expert wix will confirm this and if this is the problem can be solved
For the time being, I look for other ways to validate the field, perhaps by doing an upstream check even if it is not the right path
Thank You
Hi,
Your code appears to be fine.
Try adding debugger; to your code after the validation begins to debug it easier.
Make sure to open the console first.
Someone can help pleaseeee.
Thank You
Hi Roi, have some help for me ?
Thank you
Hello Roi,
thank you for answering me and for your help
This is the link to the page with the code
https://www.danielphoto.it/admin
Thank you
Hi,
Can you please share a link to your site and specify the name of the page ?
Roi
Can anyone help me, please?
Tahk you