I need to calculate the total value (number) of 4 inputs and make a correspondance with a number in my database.
If the total value of the 4 inputs match the number in the database, it show/allows de validation button.
If not, the validation button must by hided/disable.
Here is something I tried (don’t laugh at me :P, beginner in auto-practice !) :
$w.onReady( () => {
$w("#datasetMB").onReady( () => {
let NbreP1 = $w('#input1').value;
let NbreP2 = $w('#input2').value;
let NbreP3 = $w('#input3').value;
let NbreP4 = $w('#input4').value;
let NbreTotal = $w("#datasetMB").getCurrentItem().totalNbreLivres;
So according to your code, if something is correct then your #buttonValider is to be shown, however yet if something is wrong your #buttonValider is still set to be shown…
Yes, my mistake. But even this the correct hide(), doesn’t work…
Also, I guess I need somewhere an onChange event : when input value is changing, button hide or show accordingly. But no idea how to organize the code.
You have to add event listeners to the input that will detect value change. Otherwise the values will be undefined.
Inside the dataset.onReady, do something like this:
$w("#input1, #input2, #input3, #input4").onChange(event => {
let allValues = [$w("#input1").value, $w("#input2").value, $w("#input3").value, $w("#input4").value];
allValues = allValues.filter(e => e);//filter out undefined values
let sum = allValues.reduce((a,b) => a + b, 0);
if ( sum === NbreTotal){
//do whatever you want
} else {
//do whatever you want;
}
})