Hide and Show a button in repeater based on a condition

I am trying to hide or show a button in a repeater. This is not working. Button appear in all or none. How to have it only in repeater that matches the condition. Thanks

$w.onReady( function () {
$w(“#dataset1”).onReady(() => {
$w(“#repeater2”).forEachItem(($item, itemData, index) => {
// console.log($item(“#text24”).text +“: " + $item(”#text24").text.toString().includes(“sponsor”) );
if ($item(“#text24”).text.toString().includes(“sponsor”)) {
$item(“#container4”).background.src = “wix:image://v1/0a7cf4_50add97aba4d47dcbdd0eaacb328e899~mv2.png/border-with-yellow-flowers-pv.png#originWidth=958&originHeight=487”
$w(‘#button1’).show();

        }  **else**  { 
           
            $w('#button1').hide(); 
           
        } 

    }); 
}); 

});

found the answer after reading docs. $item instead of $w

You can also try this

import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
import wixWindow from ‘wix-window’;

$w.onReady( function () {

$w(“#repeater1”).onItemReady( ($w, MyCollection) => {

[console.log(MyCollection.My](console.log(MyCollection.My) [u]FieldCondition[/u] );     

if ( [MyCollection.My](console.log(MyCollection.My) FieldCondition === true ) {

    $w("#myButton").label = "My message"; 

} 

else {

    $w("#openCampButton").hide();   

} 

        }); 

});

It’s 7 months later, one would hope he’s not still waiting for a reply

Agree. I’m just posting it in case someone comes looking for the same answer.

2 Likes

Like me!