I have tried for over a week to solve this problem and begin to feel desperate. The good part is that the image is uploaded and inserted to the collection and in the right field column but how fun is that when it is uploaded to the wrong member? (wrong row in the database). I have tried with different codes and this is my latest alternative. Please tell me what is wrong in this one and I would be very thankful if you can write a full working code:
import { currentMember } from 'wix-members';
export function uploadButton_change(event) { currentMember.getMember() .then((member) => { const id = member._id; const fullName = `${member.contactDetails.firstName}`; return member; }) .catch((error) => { console.error(error); }); $w("#uploadButton").collapse(); $w("#text399").collapse(); $w("#text400").show(); $w("#dataset3").setFieldValue("picture"); $w("#dataset3").save(); }
Okay, then I misunderstood you. I thought you meant that I shall not combine the code with dataset-connections but now I understand that you mean that I shall not combine with settings inside the database property panel" 🙂 Sometimes I don´t fully understand the english explanations.
From one thing to another; I have tried to find a page that explains signs like }); but have not found anything about that.
I assume you are using a dataset and you also use the property-panel of your dataset and do some setups inside of it.
And additionaly you try to manage a part of functionality, by own created code.
In most cases, such a MIX goes nowhere and do not work, like in your case as you can see.
Everytime when you try to mix DATASET+SETUP inside of PROPERTY-PANEL (provided dataset-options), you should think about some very important code-lines like....
Yes this is exactly what will happen if you simply set it up inside of the property-panel --> a normal saving-process.
But you do not want just to save something inside collection, YOU WANT TO SAVE MODIFIED DATA inside of your collection.
1) Before you can use a dataset --> you first have to wait that it is ready to be used...
$w('#dataset').onReady(()=>{..your code here ..});
2) onBeforeSave-HOOK:
$w('#dataset').onBeforeSave(()=>{ //code running before SAVE-PROCESS... });
3) onAfterSave-HOOK:
$w('#dataset').onAfterSave(()=>{ //code running after SAVE-PROCESS... };
Using --> onBeforeSave-HOOK, makes sure, that you are able to modify data --> BEFORE <-- the save-process starts.
Also not very clear how you determine the uploaded data, i assume you also just connected it somewhere inside of the property-panel of the dataset.
Where is the code, for the upload-process?
An example ho it normaly could/would work...
import{currentMember}from 'wix-members'; $w.onReady(()=>{ $w('#dataset3').onReady(()=>{ $w('#uploadButton').onChange(()=>{ $w("#dataset3").save(); }); }); }); $w('#dataset3').onBeforeSave(()=>{ //start here your code-modification........ //...CODE to be done before starting save-process... //WHAT DO YOU HAVE TO KNOW FIRST ? // 1) ---> MEMBER-ID let memberID = getMemberID(); console.log(memberID); //2) ---> UPLOAD-PROCESS? --> url of uploaded-file? //...let picURL = ????????????????; //.. //. //What else is missing? //3) .....???..... $w("#dataset3").setFieldValue("picture", "picURL"); }); $w('#dataset3').onAfterSave(()=>{ //...CODE to be done after starting save-process... }); }); function getMemberID() { currentMember.getMember() .then((member)=>{ constid=member._id; constfullName=`${member.contactDetails.firstName}`; return member; }).catch((error)=>{console.error(error);}); }
Just an example of how it could look like.
Of course there are also other possibilities of how to solve it.