# How to show button on repeater only for admins and item owner?

**URL:** <https://forum.wixstudio.com/t/how-to-show-button-on-repeater-only-for-admins-and-item-owner/10615>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [November 12, 2022, 9:55am UTC](https://forum.wixstudio.com/t/how-to-show-button-on-repeater-only-for-admins-and-item-owner/10615 "2022-11-12T09:55:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![flocktravel1](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/flocktravel1/32/21017_2.png) [@flocktravel1](https://forum.wixstudio.com/u/flocktravel1)\
**Post date:** [November 12, 2022, 9:55am UTC](https://forum.wixstudio.com/t/how-to-show-button-on-repeater-only-for-admins-and-item-owner/10615/1 "2022-11-12T09:55:29Z")

</div>

Hello Everyone,

I have buttons on repeater which shows only to the user who created it. Code works just fine. Now I would like to show these buttons for admin (Myself) so even I can modify the content without accessing the Database. Could anyone please help?

```javascript
Here below is the working code to show buttons only to item owner. 

```

```javascript
$w("#repeater9").onItemReady(($item, itemData, index) => {

        if (itemData._owner === wixUsers.currentUser.id) {
            $item('#vectorImage4').show();
            $item('#vectorImage3').show();
            } else {
            $item('#vectorImage4').collapse();
            $item('#vectorImage3').collapse();
        }
    });

```

Thanks in advance 🙂

---

<div class="post-metadata">

**Author:** ![flocktravel1](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/flocktravel1/32/21017_2.png) [@flocktravel1](https://forum.wixstudio.com/u/flocktravel1)\
**Post date:** [November 13, 2022, 4:44pm UTC](https://forum.wixstudio.com/t/how-to-show-button-on-repeater-only-for-admins-and-item-owner/10615/2 "2022-11-13T16:44:53Z")

</div>

Could anyone help please?

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [November 13, 2022, 10:09pm UTC](https://forum.wixstudio.com/t/how-to-show-button-on-repeater-only-for-admins-and-item-owner/10615/3 "2022-11-13T22:09:46Z")

</div>

When you add a console-log on the following line…

```javascript
$w("#repeater9").onItemReady(($item,itemData,index)=>{
	console.log("Item-Data: ", itemData);
	//....
	//...

```

…what do you get as RESULTS ???

Another question, do you work with DATASET ?  
Did you code the rest of your setupt ?  
Did you use PROPERTY-PANEL ?  
Where is the wix-users-API-import → not shown in your code! Did you show your whole related code?

Why do you use the old and depricated USERS-API ???  
Why you do not use the new one → MEMBERS-API ?

---

<div class="post-metadata">

**Author:** ![flocktravel1](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/flocktravel1/32/21017_2.png) [@flocktravel1](https://forum.wixstudio.com/u/flocktravel1)\
**Post date:** [November 14, 2022, 10:58am UTC](https://forum.wixstudio.com/t/how-to-show-button-on-repeater-only-for-admins-and-item-owner/10615/4 "2022-11-14T10:58:00Z")

</div>

Hi Here is my entire code on my page.  
Yes I work with Data set.  
Yes I used property panel.  
The code was written by someone else and I did few modification to the code to suit my requirement.

I have imported wix users in another part in the same page. The code is very lengthy I am not able to copy everything here.

```javascript
import wixUsers from 'wix-users';

```

I tried to write below code but it does not work. I am not sure how to write async as I am still beginner.

Everything works now. Only owner can delete and edit the comment. It would be better if admin has to access to this functionality.

let roleName = ‘’  
wixUser.currentUser.getRoles()  
.then( (roles) =\> {  
let firstRole = roles[0];  
roleName = firstRole.name;  
} );  
if (itemData.\_owner === wixUsers.currentUser.id || roleName == ‘Admin’) {…}

```javascript

import wixData from 'wix-data';
import FilterWords from 'bad-words';
import wixWindow from 'wix-window';
import {sendEmail, sendEmailWithRecipient} from 'backend/email';
import wixUsers from 'wix-users';

let filterWords = new FilterWords();

$w.onReady(() => {

    $w('#checkbox1').checked = false
    if ($w('#checkbox1').checked === true) {
        $w('#button16').enable();
    } else $w('#button16').disable();

    $w('#dynamicDataset').onReady(() => {
        let currentItem = $w('#dynamicDataset').getCurrentItem()
        if (currentItem.commentsDisabled) {
            //handle what happens if comments is disabled. For example you can collapse the input
            $w('#addCommentButton').disable()
            $w('#addCommentButton').label = "RSVP Closed";
            $w('#textBox1').disable()
            $w('#textBox2').disable()
            $w('#textBox3').disable()
            $w('#textBox4').disable()
            $w('#columnStrip24').collapse()
            $w('#text253').text = ""
            $w('#text252').text = ""
            $w('#text245').text = "RSVP Closed"
            $w('#text246').text = "RSVP Closed"
            $w('#text251').text = "The required flock size has been met, hence RSVP is closed for this travel flock."
            $w('#image6').show()
            $w("#errorText").text = "Comments disabled"
            $w("#errorText").show()
            console.log("disabled")
            } 
            })

    $w("#repeater9").onItemReady (($item, itemData, index) => {
           
          if (itemData._owner === wixUsers.currentUser.id) {
            $item('#vectorImage4').show();
            $item('#vectorImage3').show();
        } else {
            $item('#vectorImage4').collapse();
            $item('#vectorImage3').collapse();
        }

        $item('#vectorImage3').onClick((event) => {
            $item('#vectorImage3').collapse();
            $item('#vectorImage4').collapse();
            $item('#thankssmiley').collapse(); 
            $item('#group71').expand();
        });

        $item('#button28').onClick((event) => {
            $item('#vectorImage3').expand();
            $item('#vectorImage4').expand(); 
            $item("#thankssmiley").expand()
            setTimeout(() => {
            $item("#thankssmiley").collapse()
            }, 5000);
            $item('#group71').collapse();
        });

        $item('#deletebutton').onClick((event) => {
            $item('#deleteloader').expand();
            $item('#group71').collapse();
            let id = itemData._id;
            wixData.remove("comments", id)
                .then(() => {
                    setTimeout(function () {
                        let totalCount = $w("#dataset1").getTotalCount();
                        $w('#text250').text = totalCount.toString() + " TRAVELERS JOINED"
                        $w("#dynamicDataset").setFieldValue("rsvpCount", totalCount)
                        $w('#dynamicDataset').setFieldValue("repeaterStatus", "OPEN TO JOIN"); 
                        $w('#dynamicDataset').save();
                    }, 2000);
                    console.log("OPEN TO JOIN")
                    $w('#dataset1').refresh();
                });
        });

        $item("#vectorImage4").onClick((event) => {
            const repeaterItem = itemData;
            wixWindow.openLightbox("Join Flock Now 1", {
                    "_id": itemData._id,
                    "excitement": $item("#text255").text,
                    "other": repeaterItem
                })
                .then((data) => {
                    //REFRESH THE DATASET WHEN LIGHTBOX CLOSES
                    $w('#dataset1').refresh()
                    $w('#dynamicDataset').refresh()
                    if (data._id) {
                        scrollToUpdatedItem(data._id)
                    }
                })
        })
         
    });
    
})

export function checkbox1_click_1(event) {
    if ($w('#checkbox1').checked === true) {
        $w('#button16').enable();
    } else $w('#button16').disable();

}

```

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [November 14, 2022, 7:17pm UTC](https://forum.wixstudio.com/t/how-to-show-button-on-repeater-only-for-admins-and-item-owner/10615/5 "2022-11-14T19:17:46Z")

</div>

Since you use the old wix-users-API, try this one…

import wixUsers from ‘wix-users’ ;

```javascript
$w.onReady(function() {
   let currentUser = wixUsers.currentUser;     
   console.log("Current-User: ", currentUser);
   let userRole = wixUsers.currentUser.role; 
   console.log("User-Role: ", userRole);
});

```

To make sure that it runs asynchronous…(but don’t think it is neccessary in this case…

```javascript
$w.onReady(async function() {
   let currentUser = await wixUsers.currentUser;     
   console.log("Current-User: ", currentUser);
   let userRole = await wixUsers.currentUser.role; 
   console.log("User-Role: ", userRole);
});

```

You normaly should get some results inside of console-logs.

…something like…

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

Once you got the role of the current user ----\> continue with your own code…

---

<div class="post-metadata">

**Author:** ![flocktravel1](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/flocktravel1/32/21017_2.png) [@flocktravel1](https://forum.wixstudio.com/u/flocktravel1)\
**Post date:** [November 15, 2022, 2:55am UTC](https://forum.wixstudio.com/t/how-to-show-button-on-repeater-only-for-admins-and-item-owner/10615/6 "2022-11-15T02:55:28Z")

</div>

I followed your instructions. Now the admin and owner can delete or edit the comments. Thank you very much for your support.
