Issue with data connected repeater and if function...

I am using a repeater to show pending requests from a dataset and I want the #soundcheckButton to expand only when the value of the ‘status’ field = APPROVED.

I have added the following code to the repeaters itemReady function, and it must be working in some way because the button element is set to collapse on page load but in the preview, it is showing up. The problem is that it’s expanding on all of the repeater items, instead of just those with the approved status.

export function requestsRepeater_itemReady($item, itemData, index) {

 // Set the dismiss button to dismiss the appointment request when clicked.
    $item("#cancelButton").onClick(async () => {
 // Disable the dismiss and approve buttons.
        $item("#cancelButton").disable();
 // Dismiss the appointment request.
 await cancelRequest(itemData, index, $w);
    });

 // Set the soundcheck button to show when request status is approved.
 const requestApproved = (itemData.status = "APPROVED");

 if (requestApproved) {
        $item("#soundcheckButton").expand();
    }
 else {
        $item("#soundcheckButton").collapse();
    }

}

I’m not sure what’s causing this and how I should fix it. I did look at using the getCurrentItem API but that didn’t make sense to me when using a repeater that is connected to a dataset?

Hello, Lmarie :raised_hand_with_fingers_splayed:

You’re setting the value of ( requestApproved) to be approved and not checking it, that’s why all elements are expanded because you’re telling the code to set each item to be approved.

What you can do instead is this:

if (itemData.status === "APPROVED") {
    $item("#soundcheckButton").expand();
} else {
    $item("#soundcheckButton").collapse();
}

And delete or comment this line

const requestApproved = (itemData.status = "APPROVED");

Try it and tell me if it worked.

Ahmad

Perfect, thank you for that!

So I’m guessing using three “=” will make it a query whereas just one “=” would try to set the value?

I’m trying to just piece things together using the forum and APIs atm but it can be a little tricky. I’d like to learn how to use corvid properly and understand the actual properties/effects of different syntax and how to put the code together. Would simply learning JavaScript help me do this or is there anything else that I could read up on more specific to corvid to get a better understanding?

I highly recommend that you take this JavaScript course:
https://www.codecademy.com/catalog/language/javascript

Awesome, I’ve been eyeing up codecademy so that’s great. Thanks so much :slight_smile:

You’re welcome Lmarie