Hi!
When the user presses button2 they’re submitting a listing form. When the user presses button2 I want their user.id saved to “dataset1” in the column numUser.
Right now, nothing is saving to the column numUser in the database. How do I fix this?
This is my lightbox code:
import wixData from 'wix-data';
import wixUsers from 'wix-users';
export function button2_click(event){
let dataset1 = {
numUser= user.id,
}
wixData.insert("dataset1", dataset1)
}
has a var “user” falling out of the sky. Please lookup docs on wix-users, the answer is out there (let currentuser = …, etc)
2) why would you want to do this? Wix already does this for you, in the _owner field per row
import wixUsers from 'wix-users';
import wixData from 'wix-data';
let user = wixUsers.currentUser
let userID = user.id
$w.onReady(function () {
});
export function button2_click(event){
let tosave = {'fieldname': userID}
wixData.insert("dataset",tosave)
}
@amelia3308 In Wix db, every row inside a collection CAN have an owner column filled. If a Member submits data to a collection, his userId is saved in the row, in the column _owner. Go to Content Manager (you know, the database spreadsheet thing), click on Manage Fields, tick “_owner”, and voila.
I gave up on using code to enter the data and used @giri-zano 's advice
In Wix db, every row inside a collection CAN have an owner column filled. If a Member submits data to a collection, his userId is saved in the row, in the column _owner. Go to Content Manager (you know, the database spreadsheet thing), click on Manage Fields, tick "_owner", and voila.
Then I used this code to compare the active user.id to the poster user.id
export function dataset2_ready() {
let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn;
$w("#input3").value = $w("#text35").text;
$w.onReady(function () {
$w("#dynamicDataset").onReady(() => {
let itemFieldName = $w("#dynamicDataset").getCurrentItem()._owner;
if (user.id === itemFieldName) {
console.log("hello post creator");
} else {
console.log("you're not the post creator" + itemFieldName + " " + user.id);
}
});
});
}
tried using this code on a dynamic page hoping it would fill the field in that repeater’s row in the database when the button on that container is pressed, but it didn’t work. Do you know how to code it into a repeater ?