Need help showing or collapsing data based on if collection field is blank.

Hi, I’m looking to render a list of services that each member in my collection provided based on whether the field for that service is blank or not. My collection is based upon members, and each service (1 - 15) is a different field in each collection item. My current code in admin mode has a general template like this:


The placeholder text for my Admin mode is “Service 2” but when rendered in live mode, this text is replaced with the service name that the member entered. Since members may or may not have all 15 of their services filled out, I’m using the following code to attempt to show or collapse each service (the following code is just for one service, there are 15 repetitions of it):

$w.onReady(function() {
let service2 = $w('#serviceBox2');
let sName2 = $w('#serviceName2').text;

if(sName2 !== "Service 2") {
    service2.show();
    } else {
        service2.collapse();
    }
}

However, it seems although the service name is linked to my collection and renders properly, the conditional statement above does not work since in code the value of sName2 is still “Service 2” and not the service name the the member inputed. Any help getting this to function properly using my current collection format (where the services are fields of a member item) would be greatly appreciated.

Note that I have tried to use dynamic repeaters, but those only seem to work on different collection items and not on different fields of the same collection item.

Hi daniel.
so when they input something the element “service2” has to show itself?

since you have collapsed it you should use the .expand() function to show it instead of the .Show() function.

Kristof.