I want a box to appear/disappear depending on the value of a boolean in a collection

Question:
I want a box to appear/disappear depending on the value of a boolean in a collection

Product:
Wix Editor

What are you trying to achieve:
I have this code:

import wixData from ‘wix-data’;

$w.onReady(function () {
wixData.query(“Unternehmen”)
.find()
.then(result => {
const gutscheinValue = result.items[0].Gutschein;
if (gutscheinValue === false) {
$w(“#box18”).hide();
} else {
$w(“#box18”).show();
}
})
.catch(error => {
console.error(error);
});
});

and want to use it on this website: Afrim Kerimi (wirtschaft-eichgraben.at)

What my code tries to archieve is make a container (box18) disappear when the boolean “Gutschein” in my Collection “Unternehmen” is false, and make it appear when the value is set to true. Im relatively new to coding and dont really know why this doesnt work.

Any help would be appreciated.

What have you already tried:
Scanveged the forums and google but didnt find anything (although i might have just missed it)

Additional information:

Don’t see anything wrong with the code. What’s the problem? Does the box refuse to appear/disappear? If so, you prob have run into the situation that a boolean in Wix-data can have 3 values: true, false and Null (=not filled out). False and Null are not the same. Just try testing on “true”, like:

if (gutscheinValue) {
$w(“#box18”).show();
} else {
$w(“#box18”).hide();
}
})

1 Like

import wixData from ‘wix-data’;

$w.onReady(function () {

wixData.query("Unternehmen")
    .find()
    .then(result => {
        const gutscheinValue = result.items[0].Gutschein; 
        if (gutscheinValue === true) {
            $w("#box18").show(); 
        } else {
            $w("#box18").hide(); 
        }
    })
    .catch(error => {
        console.error(error);
    });

});

I tried this now and it also doesnt work. It hides the box everywhere, changing hide and show makes it appear everywhere.

You are doing the same query every time and select the same first row (0) for the Gutschein value. What are you trying to achieve? Also, how is the default value of the box set, to Hidden or not?