- You don’t have to define it doubled…
if (total === 1 ){
$w('#bInscription').enable();
$w('#errorReco').hide();
}
if (total !== 1 ){
$w('#bInscription').disable();
$w('#errorReco').show();
}
Correct way…
if (total !== 1 ){
$w('#bInscription').disable();
$w('#errorReco').show();
}
else {
$w('#bInscription').enable();
$w('#errorReco').hide();
}
- Working with DATASETS → you always need to wait for your dataset first, until it is ready…
$w.onReady(()=>{console.log("Page is ready...);
$w('#dataset1').onReady(()=>{
console.log('Dataset ready);
$w('#iParrain_input').onChange(()=>{
console.log("INPUT-CHANGED!!!!!");
//all the rest of your code here....
//all the rest of your code here....
//all the rest of your code here....
//all the rest of your code here....
//all the rest of your code here....
//all the rest of your code here....
//all the rest of your code here....
//all the rest of your code here....
//starting a function.....
myFunction();
});
});
});
-
I am almost sure, that i already saw this INCORRECT-CODE somewhere.
Didn’t i already replied? Do you have a second opened POST ???
-
Generating your wished function …
function myFunction() {
//CODE of FUNCTION...
//CODE of FUNCTION...
//CODE of FUNCTION...
//CODE of FUNCTION...
//CODE of FUNCTION...
}
Work more logicaly…
After you have read the provided POST, you also will be able to work with RETURNING-FUNCTIONS.
You also will be able to recognize the new presented CODE-SYNTAX.
You also will be able to USE-Wix-DATA to get your results from dATABSE.
You also will be able to recognise when to use ASYNC-AWAIT!
BTW… WHAT IS ASYNC-AWAIT ? CAN I EAT IT ?
First try to learn JS-BASICS, before you try to go deeper into coding.
And when you have done all your homework…your result should look like this one, later…
$w.onReady(()=>{console.log('Page is ready...');
$w('#dataset1').onReady(()=>{
console.log('Dataset ready...');
$w('#iParrain_input').onChange(()=>{
console.log("INPUT-CHANGED!!!!!");
let inpValue = $w('#iParrain_input').value;
console.log("My-Value: ", inpValue);
//all the rest of your code here....
//all the rest of your code here....
//all the rest of your code here....
//all the rest of your code here....
//all the rest of your code here....
//all the rest of your code here....
//all the rest of your code here....
//all the rest of your code here....
//starting a function.....
myFunction(inpValue);
});
});
});
function myFunction(inpValue) {
let filter = wixData.filter();
filter = filter.eq("idClient", inpValue);
$w("#dataset1").setFilter(filter)
.then((res)=>{console.log(res);
let total = Number($w('#dataset1').getTotalCount());
console.log(total);
if (total !== 1 ){
$w('#bInscription').disable();
$w('#errorReco').show();
}
else {
$w('#bInscription').enable();
$w('#errorReco').hide();
}
}).catch((err)=>{console.log(err);})
}
In this case —> using your dataset to set the filter.
Pay attention onto the ORANGE-MARKED CODE-PART.
Take a look into CONSOLE, what do you het ?
2-different scenarios are possible…
a) you get some results → inspect them and use them.
b) you get nothing → in this case → use the → catch().-method to catch the ERROR.