Hello everyone! I’ve run into a strange problem that I’m not sure how to solve. Apologies if I’ve made any obvious mistakes, but I’m quite new to Wix Code!
I’ve created a form on one of my pages, with a submit button at the bottom. On clicking this button, I’d like the user ID to be recorded along with all the other data, by using the OnClick event for the submit button (button_1). The value of input1 is recorded correctly, but it seems the userID field keeps getting recorded during the very short time that the user is clicking on the button:
As you can see, multiple entries of the same user ID are created at 00:25, whereas I would ideally only want one. This is my code:
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () {
//TODO: write your page related code here...
});
export function button1_click(event) {
//Add your code for this event here:
let userId = wixUsers.currentUser.id;
let NewOrder = {
"Title": $w("#input1").value,
};
wixData.insert("Orders", NewOrder)
("Orders").setFieldValue('userid',userId);
}