[SOLVED] Collapse only empty text fields for repeater items

Hello! I am currently creating a repeater containing member bios. Some members have roles assigned to them, which is populated in my database as a text field. However some members do not have a role, and I am looking for a way to collapse the empty text field that would display their role.
I have found a way to collapse all the role text fields for all repeater items, but I want a way where only empty text fields are collapsed for some repeater items.

Here is what I have so far:

$w("#repeater1").onItemReady(($item, itemData, index) => {
 if (itemData.role === undefined) {
  
 }
});

As you can see, I’m not 100% sure of a way to collapse the specific empty text fields. Thank you for reading and I appreciate any help!

Hi Joanneh!

Inside your if statement simply add the name of the element and use the collapse( ) function that exists for the element.
It should look something like this:

$w("#repeater1").onItemReady(($item, itemData, index) => {
 if (itemData.role === undefined) {
    $item("#yourTextElement").collapse()
 }
});

I’m not sure as if the itemData.role should be compared to undefined or to " " (as in empty string).
If one doesn’t work just try the other. It depends on the type of your field.

Let me know if it works for you.

Doron.

Hello Doron!

Thank you for your help (: I’ve tried putting in my text element into the code you provided, so the new code looks like so:

$w("#repeater1").onItemReady(($item, itemData, index) => {
 if (itemData.role === undefined) {
    $w("#text55").collapse()
 }
});

However it still collapses the roles for all repeater items, when I would like only the blank roles to be collapsed… is there a way I can execute the collapse on only certain repeater items on not on all of them?

@joanneh You should have:
$item(" #text55 ").collapse();

@yisrael-wix Thank you Yisrael!!! That was exactly it!!! It finally works WOOHOO!!! Have a wonderful day :smiley: