# How to hide a repeater element depending on a field value?

**URL:** <https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404>\
**Category:** Ask the community\
**Tags:** wix-members-area, question, code\
**Created:** [July 24, 2021, 1:18am UTC](https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404 "2021-07-24T01:18:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![valeurie](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/valeurie/32/8755_2.png) [@valeurie](https://forum.wixstudio.com/u/valeurie)\
**Post date:** [July 24, 2021, 1:18am UTC](https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404/1 "2021-07-24T01:18:59Z")

</div>

I’m new to velo and hope someone will be able to help me figure out how to get to the solution I’m looking for.

My page has a repeater connected to a collection; items in the repeater are connected to data. Each instance in the repeater contains the name of a business from the dataset. If the business is a member of the association I want a button under their name that links to their website. If the business is not a member, I want to hide the button.

I used this code to make the buttons go away (yay!) but don’t have a clue what to do next.

let repeaterData = $w(“#myRepeater”).data;  
$w(“#button43).hide();

The database has a field with the values “yes” for members and “no” for non-members. How can I query the database to see if the value is yes or no, and then hide the button if it is no?

---

<div class="post-metadata">

**Author:** ![tony-brunsman](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@tony-brunsman](https://forum.wixstudio.com/u/tony-brunsman)\
**Post date:** [July 24, 2021, 8:54pm UTC](https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404/2 "2021-07-24T20:54:38Z")

</div>

@valeurie Have a look at the [onItemReady](https://www.wix.com/velo/reference/$w/repeater/onitemready) function. You will be able to do the check for each item in the repeater, something like this where I’m calling your yes/no field “fieldValue”.

```javascript
$w.onReady(function () {
4 $w("#myRepeater").onItemReady(($item, itemData, index) => {
        if (itemdata.fieldValue === "yes"){
              $w(“#button43).show();
        } else {
              $w(“#button43).hide();
        }
10 });
11});

```

---

<div class="post-metadata">

**Author:** ![valeurie](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/valeurie/32/8755_2.png) [@valeurie](https://forum.wixstudio.com/u/valeurie)\
**Post date:** [July 26, 2021, 3:50am UTC](https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404/3 "2021-07-26T03:50:25Z")

</div>

@anthonyb, thanks! That got me going in a productive direction, but I’m not there yet. I’ve checked that the logic and string values work, but this code hides #button43 regardless of the value of itemData . status.

$w . onReady ( **function** () {  
$w ( “#repeater1” ). onItemReady (( $item , itemData , index ) =\> {  
console . log ( itemData . status );  
**if** ( itemData . status === “n” ) {  
$w ( “#button43” ). hide ();  
} **else** {  
$w ( “#button43” ). show ();  
}  
});  
});

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [July 26, 2021, 4:52am UTC](https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404/4 "2021-07-26T04:52:54Z")

</div>

@valeurie If …  
$w ( " [#button43](https://www.wix.com/velo/forum/search/~num~button43) " ). hide ()  
Is inside REPEATER, than use…  
$item ( " [#button43](https://www.wix.com/velo/forum/search/~num~button43) " ). hide ()  
… instead $w

---

<div class="post-metadata">

**Author:** ![valeurie](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/valeurie/32/8755_2.png) [@valeurie](https://forum.wixstudio.com/u/valeurie)\
**Post date:** [July 26, 2021, 2:14pm UTC](https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404/5 "2021-07-26T14:14:43Z")

</div>

Success! Thank you!

Here’s the code that works:

$w . onReady ( **function** () {  
$w ( “#repeater1” ). onItemReady (( $item , itemData , index ) =\> {  
$item ( “#button43” ). show ()  
console . log ( itemData . status );  
**if** ( itemData . status === “n” ) {  
$item ( “#button43” ). hide ();  
} **else** {  
$item ( “#button43” ). show ();  
}  
});  
});

---

<div class="post-metadata">

**Author:** ![valeurie](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/valeurie/32/8755_2.png) [@valeurie](https://forum.wixstudio.com/u/valeurie)\
**Post date:** [August 16, 2021, 9:39pm UTC](https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404/6 "2021-08-16T21:39:31Z")

</div>

I’m back again with a follow-on. The code above worked to suppress a button in one repeater, but now I need to do the same thing for an additional 6 repeaters. Here’s what I’ve tried so far, without success:

$w.onReady(function () {  
$w(“#repeater1”).onItemReady(($item, itemData, index) =\> {  
$item(“#button43”).show()  
if (itemData.status === “n”) {  
$item(“#button43”).hide();  
} else {  
$item(“#button43”).show();  
}  
});

$w(“#repeater2”).onItemReady(($item, itemData, index) =\> {  
$item(”#button51”).show()  
if (itemData.status === “n”) {  
$item(“#button51”).hide();  
} else {  
$item(”#button51”).show();  
}  
});

$w(“#repeater3”).onItemReady(($item, itemData, index) =\> {  
$item(”#button52”).show()  
if (itemData.status === “n”) {  
$item(“#button52”).hide();  
} else {  
$item(”#button52”).show();  
}  
});

$w(“#repeater4”).onItemReady(($item, itemData, index) =\> {  
$item(”#button53”).show()  
if (itemData.status === “n”) {  
$item(“#button53”).hide();  
} else {  
$item(“#button53”).show();  
}  
});

$w(“#repeater7”).onItemReady(($item, itemData, index) =\> {  
$item(”#button56”).show()  
if (itemData.status === “n”) {  
$item(“#button56”).hide();  
} else {  
$item(”#button56”).show();  
}  
});

$w(“#repeater8”).onItemReady(($item, itemData, index) =\> {  
$item(”#button57”).show()  
if (itemData.status === “n”) {  
$item(“#button57”).hide();  
} else {  
$item(”#button57”).show();  
}  
});

$w(“#repeater5”).onItemReady(($item, itemData, index) =\> {  
$item(”#button54”).show()  
if (itemData.status === “n”) {  
$item(“#button54”).hide();  
} else {  
$item(”#button54”).show();  
}  
});  
});

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [August 17, 2021, 1:22am UTC](https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404/7 "2021-08-17T01:22:58Z")

</div>

```javascript
$w.onReady(function () {
    $w("#repeater1").onItemReady(($item, itemData, index) => {
        $item("#button43").show();
        if (itemData.status==="n") {$item("#button43").hide();}
        else {$item("#button43").show();}
    });

    $w("#repeater2").onItemReady(($item, itemData, index) => {
        $item("#button51").show()
        if (itemData.status==="n") {$item("#button51").hide();}
        else {$item("#button51").show();}
    });

    $w("#repeater3").onItemReady(($item, itemData, index) => {
        $item("#button52").show()
        if (itemData.status==="n") {$item("#button52").hide();}
        else {$item("#button52").show();}
    });

    $w("#repeater4").onItemReady(($item, itemData, index) => {
        $item("#button53").show()
        if (itemData.status === "n"){$item("#button53").hide();}
        else {$item("#button53").show();}
    });

    // .... and so on ......
    //...
    //...
});

```

Next time → please use → CODE-BLOCK, to show your code in an nicely formated view → like i do!

---

<div class="post-metadata">

**Author:** ![valeurie](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/valeurie/32/8755_2.png) [@valeurie](https://forum.wixstudio.com/u/valeurie)\
**Post date:** [August 22, 2021, 9:05pm UTC](https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404/8 "2021-08-22T21:05:01Z")

</div>

@russian-dima will do, thanks! Did you have a solution for me, in addition to the helpful tip on formatting?

---

<div class="post-metadata">

**Author:** ![pekrzyz](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/pekrzyz/32/27981_2.png) [@pekrzyz](https://forum.wixstudio.com/u/pekrzyz)\
**Post date:** [August 23, 2021, 5:34am UTC](https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404/9 "2021-08-23T05:34:08Z")

</div>

Just to clarify, is it one repeater, that is repeated 6 times on the page, or is it 6 unique repeater objects?

If it is one repeater, but repeated multiple times, then the button name doesn’t change for every additional repeater, it is the same.  
But you would need to iterate through each of the repeaters in the collection of repeaters displayed.

Eg: something like,  
$w.onReady(function () {  
$w(“#repeater1”).forEachItem( ($item, itemData, index ) =\> {  
$item(“#button43”).show()  
if (itemData.status === “n”) {  
$item(“#button43”).hide();  
} else {  
$item(“#button43”).show();  
}  
});

---

<div class="post-metadata">

**Author:** ![valeurie](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/valeurie/32/8755_2.png) [@valeurie](https://forum.wixstudio.com/u/valeurie)\
**Post date:** [August 23, 2021, 5:42pm UTC](https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404/10 "2021-08-23T17:42:02Z")

</div>

Thanks! I think your code indexes items contained in the repeater? I have 6 unique repeaters, #repeater1, #repeater2, etc.

My code (see above) works for the first repeater, but not for the rest. I tried replacing .onItemReady with .forEachItem, but that did not work for any of the repeaters.

Do I need to call $w.onReady for each repeater?

---

<div class="post-metadata">

**Author:** ![valeurie](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/valeurie/32/8755_2.png) [@valeurie](https://forum.wixstudio.com/u/valeurie)\
**Post date:** [August 25, 2021, 9:30pm UTC](https://forum.wixstudio.com/t/how-to-hide-a-repeater-element-depending-on-a-field-value/36404/11 "2021-08-25T21:30:36Z")

</div>

Thanks for your help! Turns out my original code worked, it was my database that was screwed up.
