Hello !
Hope you are fine !
Here is my code of light box ,where there is a form, to submit status (text) to database —
$w.onReady(function () {
//TODO: write your page related code here...
});
import wixData from 'wix-data';
import wixUsers from 'wix-users';
export function button2_click(event) {
let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn;
if (isLoggedIn) {
wixData.query("Members/PrivateMembersData")
.eq("_id", wixUsers.currentUser.id)
.find()
.then((results1) => {
let toInsert = {
"fullName": results1.items[0].firstName,
"userId" : userId
};
wixData.insert("UserStatuses", toInsert)
.then( (results) => {
let item = results; //see item below
} )
.catch( (err) => {
let errorMsg = err;
} );
})
}
}
Now code of my page where there is a repeater. Inside it a button and some more elements —
import wixUsers from 'wix-users';
$w.onReady(function () {
let user = wixUsers.currentUser;
let userId = user.id;
$w("#dataset2").onReady(() => {
$w("#repeater1").forEachItem(($w, itemData, index) => {
let item = $w("#dataset2").getCurrentItems();
let val = item.userId;
if (val == userId) {
$w('#button3').show();
} else {
$w('#button3').hide();
}
});
});
});
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
export function button3_click(event) {
let currentItem = $w("#dataset2").getCurrentItem();
wixWindow.openLightbox('DELET', currentItem)
}
What I am trying to do is to –
- From the lightbox form, I get the userid of the member who submitted the form and insert it into database.
- In the 2nd page, I get the userid of the current viewing member.
- Then, in the repeater, the button will only show in those containers (of the repeater) that matches the userid (from the database) = current userid.
But the above mentioned code is not working.
Can anyone point out the mistake.
Thanks,
Ajith