How to display a text element depending on a boolean value in a collection?

Hi !
I wish to display a text element according to whether a boolean is true or not in a collection.

Here is the code I tried, but it doesn’t work :


$w("#dynamicDataset").onReady(() => {  
let items = $w("#dynamicDataset").getCurrentItem().dispo; 
if (items === true) { 
$w("#text113").show; 
}
});

the boolean field is named “dispo”

Thanks !

Hi

Change your code as follow (just tested, works fine):

 $w("#dynamicDataset").onReady(() => { 
let items = $w("#dynamicDataset").getCurrentItem(); 
if (items["dispo"]) { $w("#text113").show(); }
else   $w("#text113").hide();
}); 

Note : “===true” is not necessary, for it’s a boolean.
You can add console.log(items); to see what a returned item looks like.

awesome, thanks !

Another question, how about when several items are displayed within a repeater ? I mean, if there are 5 items in a repeater, and that 3 of them have this field checked, I’d like the text to be displayed only on those three.

You just have to parse the repeater :

 $w("#repeater1").forEachItem( ($w, itemData, index) => {
 // Check the corresponding index in dataset
 $w("#dynamicDataset").getItems(index, 1) .then( (result) => { 
// Perform the check and hide/show (same code as above)
...

Amazing, thanks a lot ! :))

Hi, I tried to modify the code so the element that shows or not is a box and it doesn’t work. I used this:

$w.onReady( function () {
$w(‘#repeater1’).forEachItem(($w, itemData, index) => {
$w(‘#dataset1’).getItems(index, 1).then((result) => {
$w(‘#dataset1’).onReady(() => {
let items = $w(‘#dataset1’).getCurrentItem();
if (items[“Subvencionada”]) {
$w(‘#box2’).toggle();
$w(‘#box2’).show()
} else
$w(‘#box2’).toggle();
$w(‘#box2’).hide();
})
})
})
})

Can somebody tell my why tho? haha
Thanks in advance!

Forgot to put the code as code hahah

$w.onReady(function () {
$w('#repeater1').forEachItem(($w, itemData, index) => {
$w('#dataset1').getItems(index, 1).then((result) => {
$w('#dataset1').onReady(() => {
let items = $w('#dataset1').getCurrentItem();
if (items["Subvencionada"]) {
$w('#box2').toggle();
$w('#box2').show()
} else
$w('#box2').toggle();
$w('#box2').hide();
})
})
})
}) 
$w.onReady(function () {
 $w("#dsnancyTankersley").onReady(() => { 
let items = $w("#dsnancyTankersley").getCurrentItem(); 
if (items["landscape"]) {                  //landscape
    $w("#vimgLandscape").hide();}
else   $w("#vimgLandscape").show();
if (items["#cityscape"]) {                 //cityscape
    $w("#vimgcityscape").hide();}
else   $w("#vimgcityscape").show();
if (items["#seascape"]) {                  //seascape
    $w("#vimgseascape").hide();}
else   $w("#vimgseascape").show();
if (items["#draw"]) {                      //draw
    $w("#vimgdraw").hide();}
else   $w("#vimgdraw").show();
if (items["#photograph"]) {                //photograph
    $w("#vimgphoto").hide();}
else   $w("#vimgphoto").show();
if (items["#figurative"]) {                //figurative
    $w("#vimgfigurative").hide();}
else   $w("#vimgfigurative").show();
if (items["#stilllife"]) {                 //stilllife
    $w("#vimgstilllife").hide();}
else   $w("#vimgstilllife").show();

});
});It is not working...

And this what i’m getting

True values = Landscape, Seascape, Still-life