Live Comment Update for Dynamic Page

Hello,

I looked through some of the past forum posts and couldn’t find the solution that I was looking for.

I was able to create a unique comment box for my dynamic wix pages using a repeater and linking it to a database. I would like for the comments to display right after the user clicks the “Submit Comment” Button. Right now the comments will only display after the page is refreshed. Is there a way to have a live comment update without having to refresh/reload the entire page?

The code that I am using is below – please let me know if more information is needed.

Thank you!

import wixData from 'wix-data';

let dynamicPageItem;

$w.onReady(() => {
    $w('#button1').onClick(saveComment);
 
});

function saveComment(event) {
    dynamicPageItem = $w('#dynamicDataset').getCurrentItem().title;
 if ($w('#textBox1').value.length > 0) {
            $w('#dataset1').setFieldValue('dynamicPageItem',   
            (dynamicPageItem));
            $w('#dataset1').setFieldValue('comment',   
            $w('#textBox1').value);
            $w('#dataset1').save();
        }
 
}

Hello Heath H-M,

I tried applying .refresh() to my database but it kept giving me an error – are there any thoughts to what could be causing this?

I tried the following:

import wixData from 'wix-data';

let dynamicPageItem;

$w.onReady(() => {
    $w('#button1').onClick(saveComment);
});

function saveComment(event) {
    dynamicPageItem = $w('#dynamicDataset').getCurrentItem().title;
 if ($w('#textBox1').value.length > 0) {
            $w('#dataset1').setFieldValue('dynamicPageItem',   
            (dynamicPageItem));
            $w('#dataset1').setFieldValue('comment',   
            $w('#textBox1').value);
            $w('#dataset1').save();
        }
     $w('#dataset1').reload(); //I tried inserting the reload here
}

I updated the line item to

$w('#dataset1').refresh();

but I got the following error:

save operation failed: DatasetError: Operation (save) not allowed during save

So I tried removing the .save() but got another error:

save operation failed: DatasetError: Some of the elements validation failed