Hi everyone,
I’ve been rattling my brain about this one for a little bit of time and i’m close but i’m not there yet. I can’t seem to get anything to work.
I currently have Books displayed on a dynamic page, and a box where it allows site visitors to write a small review for the book. Underneath this, I have a repeater that displays these reviews.
When user submits the form, the data gets added to PeerReviews (collection2), I also need this upload to add the review to the multireference in my Books collection (collection1).
I have tried using the variants of the wix-data api and the multireference inserts etc but nothing seems to work.
When i upload the review, the item is given in JSON with the _id value, but it won’t let me add this value to the multireference in the Books collection (collection1).
Here is my upload click on the dynamic book page that uploads the data to PeerReviews collection, apologies, it’s not the cleanest code or probably the most efficient. Any help would be appreaciated.
export function submitreviewBtn_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
// Add your code for this event here:
$w('#preloaderdynamic').show();
var str = $w('#firstnamereview').value;
if (str.substr(0,str.indexOf(' ')) !== ""){
str.substr(0,str.indexOf(' '));
console.log(str.substr(0,str.indexOf(' ')));
$w('#firstnamereview').value = str.substr(0,str.indexOf(' '));
let toInsert = {
"title": $w('#BookTitle').text,
"firstName": str.substr(0,str.indexOf(' ')),
"userRating": $w('#userratingreview').value,
"schoolName": $w('#schoolnamereview').value,
"review": $w('#userreview').value,
};
wixData.insert("PeerReviews", toInsert)
.then( (results) => {
let item = results; //see item below
console.log(item);
$w('#preloaderdynamic').hide();
ClearAllUserReview();
} )
.catch( (err) => {
let errorMsg = err;
$w('#preloaderdynamic').hide();
} );
}else{
str = $w('#firstnamereview').value;
console.log(str)
$w('#firstnamereview').value = str;
let toInsert = {
"title": $w('#BookTitle').text,
"firstName": str,
"yearGroup": $w('#yeargroupreview'),
"userRating": $w('#userratingreview').value,
"schoolName": $w('#schoolnamereview').value,
"review": $w('#userreview').value
};
wixData.insert("PeerReviews", toInsert)
.then( (results) => {
let item = results; //see item below
console.log(item);
$w('#preloaderdynamic').hide();
ClearAllUserReview();
} )
.catch( (err) => {
let errorMsg = err;
$w('#preloaderdynamic').hide();
} );
}
console.log(str.substr(0,str.indexOf(' ')));
}