Adding a comment box on item's pages

Hi !

I know there has been several threads about it, but no concrete answer.

Is it possible to have a unique comment box on each item’s page ?

I tried the “Comments” app and it shows every comment that has been posted on every item’s page.
I’ve set Disqus, but I’m not sure if it will work or not (+ Disqus is not so great).

Also, if the item’s URL was to change (since it automatically changes the title’s name in the URL) would it be a problem with Disqus ? I know it does with Facebook comments.

I’ve seen that the new Wix Blog has a very nice comment box, only it comes with the blog app, and no seperate app is available ! :(((

If anyone has a solution : we are many to want this feature ! :slight_smile:

1 Like

I’m not familiar with these stuff :slight_smile: But i think you can create another database for all the comments been made and choose to show it on dynamic page by filtering it with whatever you show on the dynamic page. So when someone adds comment (which is a form itself) you add one more field to pick the value of whatever page that is so you can set comments to be shown by that filter.

I have no idea how would this effect the page loading time though. You can set a button for show comments or such which also filters the comments database by that dynamic page data

To be more clear:

Let’s say that you are showing an item on your dynamic page which is displayed on “#text1¹”
You have to create a comments² DB to collect the comments. You should have 2 fields on that DB
one for the comment itself and two for getting the item³ from dynamic page

Then you can use:

$w('#comments²').setFieldValue('item³', $w('#text1¹).text 

to force your comment form to add dynamic page item to your item field in comments database.
and add this code on your show comments button onclick event:

wixData.query('comments²')
    .eq('item³', $w('#text1').text)
    .find()
    .then(res => {
      $w('#table1').rows = res.items;
    });
}
//'#table1' here is where you are choosing to show your comments. 

which will show only the data on your comments² database which is equal to that dynamic page’s ‘#text1¹’.text value on item³ field.

Hi Mert ! :slight_smile:

I’ve thought of this as well, so for it to work it should retrieve the current URL and add it to a field so comments are shown depending on what the URL is.
The thing is the URL can then never be changed (For now I have a /ID/Title URL, and whenever I change the title, the URL does), but let’s say I remove the title from items’ URLs so only the ID (which is unique and never changes) remains, what would be the code then ?

here is a bit of code I previously used to get the URL and put it in a textfield :

import wixData from 'wix-data';
import wixLocation from 'wix-location'; 

$w.onReady(function () {
    let url = wixLocation.url;
    $w("#input2").value = url;
});

Why you just want to pick the url? any unique thing on that dynamic page would do it.
You can also use the id, item name whatever you want to. Just place it somewhere on the dynamic page and get it’s value on your comment form.

I’m trying exactly the same thing now for my profile page photos section
Going to create a photos DB and filter it by that specific username before showing
It should work IMO give it a try :slight_smile:


You are just putting it wrong i guess.
it works here:

$w.onReady(function () {
	$w("#input2").value = wixLocation.url;
}	

You can use wixLocation.path also

I may have multiple entries that have the same name, the only thing that makes every item unique is it’s ID :slight_smile:

Okay I see now what you mean !

I will give it a try and get back to you ! Thanks !

Maybe i am doing something wrong here wixLocation.path didn’t work :slight_smile: but wixLocation.url does :wink: (in case u missed to see check the last message before yours)
All you need now is a comments DB and extra field for dynamic pages URL on that DB.
and the filter will be:

wixData.query('comments²') 
    .eq('item³', wixLocation.url) 
    .find() 
    .then(res => { 
        $w('#table1').rows = res.items; 
    }); 
} 

I’m having errors :

$w.onReady(function () {
$w("#dataset2").onReady( () => {
		$w('#commentaires').setFieldValue('reference', $w('#input2').value;
		wixData.query('commentaires') 
    	.eq('reference', wixLocation.url) 
    	.find() 
    	.then(res => { 
        	$w('#repeater5').rows = res.items; 
    )};

 });
});

isn’t this conponent below supposed to be the ‘text1’ ?

$w('#commentaires').setFieldValue('reference', $w('#text1').text;

#commentaires = Database
reference : ID field in database
#repeater5 = repeater that displays comments
input2 = where the ID is going

No it’s the database but you have to use that line on the comment form

 $w('#commentaires').setFieldValue('reference', $w('#text1').text; 

to make possible whenever a comment is added also the page url is added to your commentaires db reference field.

Only then you can filter it by reference
Currently you don’t seem to be collecting data for your commentaires db’s reference field.

You need to have 2 fields in your commentaries DB
1for reference
2for comment

 $w('#commentaires').setFieldValue('reference', $w('#text1').text; 
                |                   |                   |
with this code  |                   |                   |
you will set    |                   |                   |
your database's<| reference field <-| to this value <---|
for the row with the comment.

Okay, I think I get it, but I don’t want to put the URL in the database, as I said, URL may change since I often make modifications. So to counter that, I use the ID. I’ve put an input (input2) that is in “read only” and that displays the current item’s ID.

So it should be like this right ?

$w(’ #commentaires ').setFieldValue(‘reference’, $w( # input2).value;

(I think .value is the correct extension for an input, instead of .text.)

It would’ve been such a pleasure to watch this struggle over here for a wix expert hahahah :slight_smile:
Feeling no need to say that this is my amateur approach you know :slight_smile:

here you can see the entire code for #repeater5 (repeater that displays comments) under the onReady

waite because I have two “commentaires” dataset :

  • datase3 : (write only) to post a comment

  • dataset2 : (read only) to display comments in a repeater

So it should be like this right ?$w(’ #commentaires ').setFieldValue(‘reference’, $w( #input2 ).value; (I think .value is the correct extension for an input, instead of .text.)

Yes now with this line you are putting #input2 value to your commentaires db reference field.
You should be able to see your reference on your commentaires db.

let me check how mine works now.
meanwhile you check your permissions. You are writing on a dataset after all by that line and have to read it on comments on the other hand

The way i have it is this.

export function ch1_onChange() {
	if ($w("#ch1").value === "TRUE") {
			$w('#dataset1').setFieldValue('username', $w('#username').value);
		}	
	else {
			$w("#userinput").value = "";
	}
}

i have a checkbox to complete before submitting the form. Here i force to put ‘#username’.value in my username filed on dataset1 (MemGenDROPS).

export function searchButton_click() {
  if ($w("#radioGroup1").value ==="RB1") {
	wixData.query('MemGenDROPS')
    .contains('title', $w('#input1').value)
    .find()
    .then(res => {
      $w('#table1').rows = res.items;
    });
	}
else {
	wixData.query('MemGenDROPS')
    .contains('username', $w('#input1').value)
    .find()
    .then(res => {
      $w('#table1').rows = res.items;
    });
    
    }
}

This on another page has a radiobutton to search by username or airdropname typed in #input1

You have both on the same page so you can use same input - text whatever you show your id on that dynamic page
and yes textbox has a .text
input has a .value
and for button you can use .label

//POST A COMMENT
	$w("#dataset3").onReady( () => {
		 $w('#dataset3').setFieldValue('reference', $w('#input2').value
		 
			/*wixData.query('commentaires') 
    		.eq('reference', wixLocation.url) 
    		.find() 
    		.then(res => { 
        		$w('#repeater5').rows = res.items; 
			});*/
	);

So I tried posting a comment, and the reference was not in the field in the database

Can you try placing a required checkbox or something else and put your setfieldvalue code under that event you can use it like i understand the commentig rules etc. :smiley: it somehow needs a trigger i guess didn’t work on onready when i tried it earlier
and make sure your commentaires db permissions are correct. created by anyone read by anyone updated and deleted by admin and also make your dataset for commentaires read&write

your #input2.value is for? i don’t see it on your codes.
Are you sure you are getting the id for your input#2 at the first place? can you see the id on input2 when you visit the page?