# Collapse and expand image if image has been uploaded in a form

**URL:** <https://forum.wixstudio.com/t/collapse-and-expand-image-if-image-has-been-uploaded-in-a-form/6935>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [February 12, 2022, 10:21pm UTC](https://forum.wixstudio.com/t/collapse-and-expand-image-if-image-has-been-uploaded-in-a-form/6935 "2022-02-12T22:21:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alloutapparel](https://avatars.discourse-cdn.com/v4/letter/a/dc4da7/32.png) [@alloutapparel](https://forum.wixstudio.com/u/alloutapparel)\
**Post date:** [February 12, 2022, 10:21pm UTC](https://forum.wixstudio.com/t/collapse-and-expand-image-if-image-has-been-uploaded-in-a-form/6935/1 "2022-02-12T22:21:10Z")

</div>

I have an image in a repeater for a reviews section. I have the image linked to the appropriate field in the dataset. I have the image set neither as ‘collapsed’ or ‘hidden’.

I have the code:

```javascript
if(itemData.image) 
{
    $w('#uploaded').expand();
}
else {
    $w('#uploaded').collapse();
}

```

and the image will not appear in any repeater box. Upon hitting a ‘load more’ button, when I get to a review within image uploaded it will show the image. But, every image will appear as well with a default selected image.

Not sure what I am doing wrong?

 ![](https://us1.discourse-cdn.com/wix/original/3X/a/8/a8bd88e2fc2d74eaba65e3411b239a65484e4b6c.png)

 ![](https://us1.discourse-cdn.com/wix/original/3X/5/d/5dcb43978fc615741d051668421eb84fd9c52154.png)

---

<div class="post-metadata">

**Author:** ![tony-brunsman](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@tony-brunsman](https://forum.wixstudio.com/u/tony-brunsman)\
**Post date:** [February 13, 2022, 6:54pm UTC](https://forum.wixstudio.com/t/collapse-and-expand-image-if-image-has-been-uploaded-in-a-form/6935/2 "2022-02-13T18:54:17Z")

</div>

@alloutapparel It’s necessary to tell Wix/Velo which particular repeated item (row) that you want to expand or collapse. There is an explanation of this in the repeater documentation [introduction](https://www.wix.com/velo/reference/$w/repeater/introduction) under the section entitled “Retrieve Repeater Item Data When Clicked”. The concept is a little abstract, but it will sink in eventually.

It sounds like you want this logic to be applied when the repeater loads. In that case, you could put it in an onItemReady function. The repeated item scope selector ($item as opposed to the normal selector $w) is the key to having the expand/collapse appropriately applied to each repeater item.

```javascript
$w("#repeater1").onItemReady( ($item, itemData, index) => {
    if (itemData.image){
        $item('#uploaded').expand();
    } else {
        $item('#uploaded').collapse();
    }
});

```

In the “load more” button, it would go like this:

```javascript
$w.onReady( function () {
  $w("#buttonName").onClick( (event) => {
    let $item = $w.at(event.context);
    let itemdata = $item("#myDataset").getCurrentItem();
    if (itemData.image){
        $item('#uploaded').expand();
    } else {
        $item('#uploaded').collapse();
    }
  });
});

```
