Hi everyone,
I am almost done with a small setup of three switches but something doesn't work when sending data to database.
Let's call them Switch #1, #2 and #3
Switch #1 is ON while #2 and #3 are OFF.
When a user activate #2, it automatically switch #1 OFF.
My Code :
export function switch1_change(event) {
$w("#switch2").checked = false;
$w("#switch3").checked = false;
if ($w("#switch1").checked === false) {
$w("#switch1").checked = true
}
}
export function switch2_change(event) {
$w("#switch1").checked = false;
$w("#switch3").checked = false;
if ($w("#switch2").checked === false) {
$w("#switch2").checked = true
}
}
export function switch3_change(event) {
$w("#switch2").checked = false;
$w("#switch1").checked = false;
if ($w("#switch3").checked === false) {
$w("#switch3").checked = true
}
}
The idea of the "if statement" is to force the switch to stay ON (user can't deactivate a switch, only select another switch and this will deactivate the two others).
The three switches are connected to a database (each one to a boolean column) and #1 is activate by default.
My problem is that if the user select another switch (#2 for exemple), the #1 deactivate well, but both booleans are checked in my database (only the #2 should be check, as the user deactivate #1).
Can someone tell me what I am doing wrong ?
TL:DR :
Three switches are "linked" by code so only one can be activated at the same time. My problem is that a deactivated switch send a "true" value in my database.
Thanks a lot !