I’ve made a comment form that has the options to the user fill their name, their picture, rate the product and leave a comment, and also the data automatically refresh after hitting the submit button, so the comment appears below on a comment section. The fields of the comment form are connected to the dataset1 and the fields of the comment section are connected to the dataset 2. Both of them have the same database, QGisB.
When I was doing this code without the name and the picture options, the refresh was working fine, but after I’ve incluid them in the code (what I probably did wrong, but I’m not seeing where now), the data started to duplicate, but with the picture and the name blank, and the refresh only works to see the first buggy comment, in order to see the second correct one, you need to refresh the entire page.
Plus, it’s appearing to be working only on the Editor now. I can’t submit any data on the published page.
Here’s the code:
import wixData from 'wix-data'
export async function submit_click(event) {
await saveComment(), $w('#dataset2').refresh()
async function saveComment (parameter) {
const newComment = $w('#commentbox').value
const newDate = new Date().toLocaleDateString()
const profilePic = $w('#uploadButton1').value
const name = $w('#nickbox').value
const rating = $w('#ratingbox').value
let toSave = {
"nick": name,
"date": newDate,
"pic": profilePic,
"comment": newComment,
"rating": rating,
};
await wixData.save("QGisB", toSave)
.then( (results) => {
if(results.items.length > 0) {
let firstItem = results.items[0];
$w('#dataset2').refresh()
}
else { }
})
.catch( (err) => {let errorMsg = err;});
}
}
I’ll be really glad if anyone could help me!