[SOLVED] Collapse all text items in repeater

Hello! I am creating a page where users can search up people and have the option of clicking on a ‘read more’ button in each container of the repeater which expands their bios. I’m trying to code an event where if the user clicks on a ‘clear search’ button, all the bios in the repeaters collapse, even if only one bio is opened by the user. This is what I have so far:

//button16 is the ‘clear search’ button
//#text82 is the bio
export function button16_click(event) {
$w(‘#text82’).collapse();
$w(‘#button15’).hide();
$w(“#button14”).show();
}

The above does not work. However if I replace the .collapse() with .expand() it does expand all the bios. How can I get it so that even if only one bio is expanded and the rest are collapsed, the code will still execute the collapse method?

Thank you for taking the time to read my question! (: Please let me know if there is anything that needs to be clarified.

Hello

On button click you need to see for each repeater item if the text box is collapsed or not and if not you collapse it, here’s an example to help:

$w('#repeater1').forEachItem(()=>{
        !$w('#text2').collapsed ? $w('#text2').collapse():null
    })  

Best
Massa

Hi Massa,

Thank you so much for your reply!
I’ve tried implementing your code and now it looks like the following:

export function button16_click(event) {
$w(‘#repeater1’).forEachItem(() => {
if (!$w(‘#text82’).collapsed) {
$w(‘#text82’).collapse();
}
})
}

It still does not work however… and I tried testing the opposite of what I want to code where the bios get expanded instead of collapsing and it works:

export function button16_click(event) {
$w(‘#repeater1’).forEachItem(() => {
if ($w(‘#text82’).collapsed) {
$w(‘#text82’).expand();
}
})
}

I’m still puzzled as to why expanding works and not collapsing… maybe Wix Code’s collapsing method has something different that makes it behave this way? I really appreciate your help :smiley:

Hello @joanneh

can you please provide me with your website’s link so i can take a look at it.

Thanks
Massa

@massasalah18 Sure! Just follow this link here: http://wix.to/3sD4AJo. To go to the specific page I am referring to go to “Coaching” and then click on “Meet Our Coaches”. Thank you so much again for your help!! (:

UPDATE: Found a solution!!!
For some reason, a simple $w(“text82”).collapse() wouldn’t work so what I did was this instead:

$w("#repeater1").onItemReady(($item, itemData, index) => {
 if (!$item('#text82').collapsed) {
            $item('#text82').collapse();
        }
    });

I think using $item was what enabled the text fields to be collapsed for all repeater items. Hope this helps for those from the future (:

Planning a Repeater based on a fiction author’s text scene. The scene text would expand to allow reading of an editor’s comments. The comments should then collapse to allow further reading of author’s text. The expansions should be adjacent to or visually linked to the section of author’s text they comment on.
In addition, it would be great to display all editorial comments in order while the author’s text is also displayed. Future tense for that. My last exposure to coding was for 1980s-era databases. So my first step must be to start (and complete) a series of text displays each followed by collapsible and expandable displays of editorial comments. Ready today to start with the preliminary chores (in addition to learning the glossary terms). I would appreciate any comments. If I seem hopelessly behind the times, I would also appreciate learning how to locate Wix coders-for-hire with the above expertise.
Alan