Hi guys i have this code but can’t get a number result only NaN
I have changed the like field in the collection between #number and #text
just not sure why this won’t give me a number
Regards
Adam
Hi guys i have this code but can’t get a number result only NaN
I have changed the like field in the collection between #number and #text
just not sure why this won’t give me a number
Regards
Adam
Hi Adam,
Next time try to copy your text and place it in a code snipit, its easyer for people to adjust.
for your problem i think it lies with the String(like+1);
try to do (like + 1).toString()
be sure your “like” column is a number otherwhse like + 1 wouldn’t work.
kind regards
Kristof.
Thanks Kristof, i have replaced that line of code, the “like” field is a number field and the #counter is connected to the “like” field by connecting data
I do only have the “like” button showing in the second repeater which mirrors what has been entered in the top one.
the code
export function like_click(event, $w) {
let Like = Number($w( ‘#dataset2’ ).getCurrentItem().Like);
let CurrentItem = $w( ‘#dataset2’ ).getCurrentItem();
let toUpdate = {
“_id” : CurrentItem._id,
“name” : CurrentItem.name,
“comments” : CurrentItem.comments,
“like” : Number($w( ‘#counter’ ).text)
};
$w( ‘#counter’ ).text = (Like + 1 ).toString()
$w( ‘#Like’ ).disable();
wixData.update( “Comments1” , toUpdate);
}
The actual like button with properties
and the collection fields
Thanks for your time
Adam
Hi adam,
Working in a repeater works a bit different when using their items.
Take a look here
https://www.wix.com/corvid/reference/$w.Repeater.html#onItemReady
To see how to use a repeaters items.
You need to use the repeated item scope selector . Like this:
let $item = $w.at(event.context);
let Like = Number($item('#dataset2').getCurrentItem().like);
let CurrentItem = $item('#dataset2').getCurrentItem();
Make sure you use field Id and not the field name. So you want like and not Like
To add to Kristof comments above before I go, there are previous forum posts that go through a like button that you can look at as well.
https://www.wix.com/corvid/forum/community-discussion/liking-posts-in-repeater-comprehensive
https://www.wix.com/corvid/forum/community-discussion/is-there-a-way-to-make-a-button-add-1-to-a-collection-field-everytime-its-pressed/p-1/dl-5d7586909e46060017124d1e
https://www.wix.com/corvid/forum/community-discussion/increment-button-with-1
https://support.wix.com/en/article/corvid-tutorial-adding-ratings-and-reviews-to-a-wix-stores-site#step-12-create-the-updatestatistics-function-in-the-review-box-lightbox
They might not help you here, however they can at least give you an idea.
Also, in your getCurrentItem line, I don’t think that your field key begins with a capital L.
Plus, does the first one need to be in a repeater, can the user review input just be a simple form with the reviews being displayed in a repeater underneath?
Hi all, i think i have followed your instructions here but still not a number
export function like_click(event, $w) {
let $item = $w.at(event.context);
let like = Number($item( ‘#dataset2’ ).getCurrentItem().like);
let CurrentItem = $item( ‘#dataset2’ ).getCurrentItem();
let toUpdate = {
“_id” : CurrentItem._id,
“name” : CurrentItem.name,
“comments” : CurrentItem.comments,
“like” : Number($w( ‘#counter’ ).text)
};
$w( ‘#counter’ ).text = (like + 1 ).toString();
$w( ‘#like’ ).disable();
wixData.update( “Comments1” , toUpdate);
}
also not sure if this link helps
https://www.vorbly.com/Vorbly-Code/WIX-REPEATERS-LIKE-BUTTONS-FOR-COMMENTS
the counter is linked to
Regards
A
and the collection shows a zero in the like field so cannot see why this would say NaN
fixed with read and write permission in settings
Well done for sorting it out, plus for future reference I forgot to add this link previously which gives you a reply from J.D. and it gives you a code example for it which sets it out as Kristof was explaining to you earlier in his reply back to you.
https://www.wix.com/corvid/forum/community-discussion/how-to-develop-a-like-button