Vorbly Code | WIX REPEATERS LIKE BUTTONS FOR COMMENTS

Vorbly <Code>

CODING MADE EASY WITH VORBLY

WIX REPEATERS LIKE BUTTONS FOR COMMENTS

Need a "like" button and counter for your comments section? This tutorial will show you how to customize your comments section with a "like" button and counter using Wix Repeater. We will provide you with the webpage elements and sample codes required to implement this feature.

THE DEMO

1/2

THE ELEMENTS

The Page

Repeater: #repeater1

  • Name: #name

  • Comments: #comments

  • Date / Time Text: #date

  • Like Button: #Like

  • Like Counter: #counter

The Database

Create a database: Comments (dataset1)

  • Name: name

  • Comments: comments

  • Like Count: like

  • Date / Time: _createdDate

Then link fields to your repeater. For this example, we use Like (like) for the like counter in the repeater.

THE CODE

Page Code

export function Like_click(event, $w) {

 

let like = Number($w('#dataset1').getCurrentItem().like);

let CurrentItem = $w('#dataset1').getCurrentItem();

let toUpdate = {

"_id" : CurrentItem._id,

"name" : CurrentItem.name,

"comments" : CurrentItem.comments,

"like" : Number($w('#counter').text)

};

$w('#counter').text = String(like +1);

$w('#Like').disable();

wixData.update("Comments", toUpdate);

 

}

COMMENTS

I'm a paragraph. Click here to add your own text and edit me. It's easy.

No comments. Be the first to leave a comment.

Hi,
I think this is a dynamic page, correct? The code seems to be working flawlessly on your website, but in my tests hitting one like button chances the counter of all repeaters at once, and I've revised the code several times using getCurrentItem() but can't seem to figure it out.

Do you have any idea why this might be?

Thanks in advance!

David

Nov 15, 2018

30

Oh, and in return for your help, I'll be sure to help you out as well, I have a couple easy fixes for you!

David

Nov 15, 2018

22

Hi David,

You are right, this sample code is for dynamic pages.

First thing that comes to mind is, did you add the "_id" field when updating your database?

If that doesn't work, please paste your code here and we will help review your code.

You are most welcome!

Andrew (Vorbly)

Nov 15, 2018

17

Hey Andrew,

Sorry for the late response but I haven't been able to even test my code properly due to the Wix update glitches over the past few days. I did copy over the ._id Now that everything seems to be working again, I think I can actually fix this. I'm assuming you have used an onItemReady condition for your repeater somewhere so that the like button works only on that comment? I fear what's going wrong with mine probably has to do with different code for how the comments function stores and works, since I pretty much copied your "like" function. Any way we could have this conversation over email so I can repay you as well?

As I said, I appreciate your help,

David

David

Nov 20, 2018

8

You're most welcome David! We are glad that you managed to implement this feature and we will connect with you via email.

Andrew (Vorbly)

Nov 20, 2018

8

WEB DESIGN & DEVELOPMENT SOLUTIONS

GET PROFESSIONAL HELP