Trying to collapse a gallery

I have 2 repeaters. Both have a gallery (the older strip gallery, not pro) in them. One is ItemRepeater1 and the other is ItemRepeater2.
I have to records in my table. They have an image field and a text field named item_sort. I want the record with sort 1 to go into repeater1 and 2 to go into repeater2. Right now that seems to work but I want the gallery to collapse if there is no image with the proper sort. My code and a screenshot is below.

wixData.query( ‘tutorials_sub1’ ).contains( ‘tutorials_top_id’ , $w( “#idBox” ).text)
.and(wixData.query( ‘tutorials_sub1’ ).contains( ‘item_sort’ , ‘1’ ))
.find()
.then((results) => {
if (results.items.length > 0 ) {

            $w( "#textBox" ).collapse(); 
            $w( "#textBox" ).collapse(); 

        }  **else**  { 

            $w( '#itemRepeater1' ).data = results.items; 
            $w( "#textBox" ).expand(); 
            $w( "#textBox" ).show(); 

        } 

    } 

) 

wixData.query( ‘tutorials_sub1’ ).contains( ‘tutorials_top_id’ , $w( “#idBox” ).text)
.and(wixData.query( ‘tutorials_sub1’ ).contains( ‘item_sort’ , ‘2’ ))
.find()
.then((results) => {
if (results.items.length > 0 ) {

            $w( "#imageBox" ).collapse(); 
            $w( "#imageBox" ).collapse(); 

        }  **else**  { 

            $w( '#itemRepeater2' ).data = results.items; 
            $w( "#imageBox" ).expand(); 
            $w( "#imageBox" ).show(); 

        } 

    } 

) 

Still need some help if anyone has some input. Maybe I’m approaching this the wrong way?

  1. Why do you have the same line twice?
    $w("#textBox").collapse(); 
    $w("#textBox").collapse();
  1. Are you sure the property id of the box is “textBox”?
  • you probably need:
if(!results.items.length > 0){

if you access an item in a repeater you have to use$item(“#textbox”) instead of $w(“#textbox”)

kristof.

If it’s in a reapter, he’ll need to use .onItemReady().
https://www.wix.com/corvid/reference/$w.Repeater.html#onItemReady

@jonatandor35
as he told he has gallary in a repeater so i gues its in a repeater :sweat_smile:
but yea if you use a repeater you have to do it in the .onItemReady() otherwhise all gallery’s collapse/expand at the same time.