I’m currently working on a page where I have a switch, when I interact with the switch I need to do this: if the switch value is true, I gotta retrieve the id of the current logged member and input it in a multiple reference field in my collection called ‘fDemandaProduto’. And if the switch value is false, I have to delete that same id. Here’s my code: (Not using any datasets)
import { currentMember } from 'wix-members';
const member = await currentMember.getMember();
async function sendUserIdToDb() {
$w('#mySwitch').onChange(async () => {
try {
if ($w('#mySwitch').checked) {
await wixData.get('fDemandaProduto', path).then(async (res) => {
res.multiReferenceField = member._id;
await wixData.update('fDemandaProduto', res);
});
} else if (!$w('#mySwitch').checked) {
await wixData.get('fDemandaProduto', path).then(async (res) => {
res.multiReferenceField = '';
await wixData.update('fDemandaProduto', res);
});
}
} catch (error) {
console.log(error, 'erro no catch 433');
}
});
}