It didn’t work Mert
1 - nope Can you make a screenshot of your comments database? I need to know how many fields you did used and how did you name them.
2 - What is “text54” ?
3- Can you also make a screenshot of your comment box so I can see how it looks like without seeing your website?
Thanks for your help!
Jakub
1- Here you can see it circled in red
In order :
-
Commentaire (comments in French) : is the actual user input (here they are irrelevant, I was just testing)
-
Pseudo : the username the user typed in
-
reference : I have a custom reference that I use for URLs, but the same exists by default : ID
-
item : this is supposed to get the current item’s title but for some reasons it doesn’t work (probably because the title is from another dataset ?)
-
last updated (default)
-
date created (default)
2- text54 is the item’s title, you don’t have to worry about that line of the code, I put it there just for some practical reasons but it doesn’t work.
3- it is not finished yet, but here you go
Thanks Tristan
One more question … How should I set it up for the Dynamic Page?
- Let’s say if I click on the link “sports cars” which will open in DP, I want specific comment box for “sports cars”.
- If I click on the link “family cars” which will open in DP, I want specific comment box for “family cars”.
But for now, if I open any of those links in DP I can see the same comments.
I can see that you are using references, but I’m not sure if I understand it well.
Thanks
Yes, you need to filter comments based on a unique criterion, such as an ID (a default ID is provided for each entry in each data collection.
What we did, Mert and I, is we fetch the item’s ID and put in an input (which I have hidden so users can’t see it) and then, we fetch this displayed ID to put it in a field along with the comment, the username etc…
this code is to be put under the OnReadyfunction :
//LIST OF COMMENTS
$w("#dataset2").onReady(() => {
//shows only item-related comments
let filter = wixData.filter();
filter = filter
.eq("reference", $w("#input2").value);
$w("#dataset2").setFilter(filter);
});
dataset2 : the name of my “read only” comment dataset
reference : the field in my comment dataset where the ID or reference if you wish is put
input2 : the hidden input where the item’s ID is displayed
so this was to filter comments according to the item.
Now to automatically put the item’s ID when the user posts a comment (there is also extra code)
//refreshes comments + goes to top of comment box upon submitting a message
export function button43_click(event, $w) {
//POST A COMMENT
//post a comment and get the item's ID
$w('#dataset3').setFieldValue('reference', $w('#input2').value);
$w("#dataset3").save()
}
button43 : the button used to submit the comment
NOTE : here button43 is disconnected from the dataset in the editor (grey icon,n ot green) , since I have manually set it to save the entry upon clicking the button
Quick Tip here:
Always name your elements by their use cases which makes everything easier to organize and progress.
It’s surely easier to remember the submitButton instead button43
That’s what i’ve been telling myself !
But I keep keeping default names aha for some reason.
The ‘replace by’ function in the search bar of the code panel is a good way to rename all elements in no time.
Now I only need a few things to be all set :
-
Get the number of comments to display them (eg : 15 comments)
-
Automatically detect URL posted in comments to make them clickable and in orange color
-
hide the ‘load more comments’ when all comments have been loaded
If anyone has a solution
Hi man,
I’m still doing something wrong about ID.
- I did pull out ID from the database:
2 - there is some mistake in code: “value is undefined”
import wixData from "wix-data";
$w("#dataset2").onReady( () => {
$w("#dataset2").onReady( () => {
let filter = wixData.filter();
filter = filter
.eq("reference", $w("#input2").value); //value is undefined
$w("#dataset2").setFilter(filter);
});
$w("#dataset3").onReady( () => {
$w('#dataset3').setFieldValue('reference', $w('#input2').value); //value is undefined
});
});
export function button43_click(event, $w) {
$w('#dataset3').setFieldValue('reference', $w('#input2').value); //value is undefined
$w("#dataset3").save()
}
You can check all it in one:
ps: I know about missing semicolon on line 26.
If you see something pls let me know. I’m going to be crazy of it xD
Thanks!
Hi !
That’s normal, that’s a text element, you need to place an input (right above ‘text’ in the wix menu) since “.value” is used for inputs, if that’s a text element, it should be “.text” but I can’t guarantee that would work so replace your text element by an input
Hi Tristan!!
Guess what? It’s workiiing !!!
At first - Thank you so much for your help!
Secondly - as you wrote above I used “.text” instead of .“value” and its working perfectly.
Love it !!
Thanks,
Jakub
Have you checked your dataset permissions?
Yes, it’s all set to: Anyone.
It doesn’t matter so much bcs my ID text is working but I’m still interesting what I’m doing wrong…
No idea, did you check the input’s settings (max length, type of input (text, URL…))?
hi i’m experiencing the same problem where my input field does not allow me to select ID even when permissions are changed!!
@ Jakub can you please upload your codes with the .text formats? I tried that and it didn’t work for me
the ids change when i swap between items but the comments still appear everywhere!!
please help!!!
if it helps i have taken a screenshot of my codes as shown below - currentPost being reference and text51 being the current input replacer!
Hi!
you can see my current code below.
It’s setup for login member only. Thats why I’m using nick (jmeno) and foto values.
export function KomRead_ready() {
let filter = wixData.filter();
filter = filter
.eq("reference", $w("#input2").text);
$w("#KomRead").setFilter(filter);
}
export function KomWrite_ready() {
$w('#KomWrite').setFieldValue('reference', $w('#input2').text);
$w('#KomWrite').setFieldValue('jmeno', $w('#input3').text);
$w('#KomWrite').setFieldValue('foto', $w('#image74').src);
}
export function save_click(event, $w) {
$w('#KomWrite').setFieldValue('reference', $w('#input2').text);
$w('#KomWrite').setFieldValue('jmeno', $w('#input3').text);
$w('#KomWrite').setFieldValue('foto', $w('#image74').src);
$w("#KomWrite").save();
$w("#KomRead").refresh();
}
for now it’s look like this:
Wish you best luck!
Jakub
I tried using the codes that you used and replaced my own values in and it didn’t work at first but then i fiddled around with it and added a few more lines here and there and i don’t know what i did exactly but it finally worked!!! thank you so much!!
show comments count-
function commentcount() {
let itemid = $w("#dynamicDataset").getCurrentItem()._id; //gets the current items id.
wixData.query('Comments') //dataset for comment
.eq('itemid', itemid) // item id feild in database
.find()
.then((results) => {
let saveit = results.items[0];
let count = results.totalCount;
$w('#text130').text =" "+count+" Comment"; // text to show ? comment.
console.log(count);
});
}
- Can we add a publication date for each comment?
- Can we allow comments only from logged-in users?