I have a user profile page, where the user can update their personal informations like name, email, living address ,etc.
(Although it is achievable using button on wix, but I would like to try through coding.)
I also added document input button called “#uploadButton1”, and this is the issue I want to solve here.
First of all, here is what I’m trying to do : (I wrote a code below)
- Click upload(submit) button on the page
- Upload (or store?) file on #uploadButton1
- assign file in #uploadButton1 on “register”
- Find the entry from the data collection that matches to the user updating info.
- set the file stored in #uploadButton1 to the field called “registration”, in the data collection
- Update the data collection with new document from #uploadButton1
Here is my problem :
Because I set $w(‘#uploadButton1’) as a “value”,
so in the data collection, it stores the text data of name and file size…
how can I select " document file " that is stored in $w(‘#uploadButton1’)??
It would be very nice if anyone could answer this!
Thank you very much in advance.
//Step 1
export function update_click(event, $w) {
**//Step 2**
$w('#uploadButton1').startUpload();
**//Step 3**
let register = $w(‘#uploadButton1’).value; //This is the document
let values;
const saId = $w(‘#saId’).text;
**//Step 4**
wixData.query("SalesAgent")
.eq("_id", saId)
.find()
.then((results) => {
**//Step 5**
values = results.items[0]; //old record
//Updating old record in code, it includes the _id field
values.registration = register;
**//Step 6**
//update only "value" field, but send all previous field as well
wixData.update("SalesAgent", values)
.then((results2) => {
**let** item2 = results2;
**const** alertSuc = $w('#succMsg').show();
$w("#sadb").refresh();
console.log( "UPDATED");
})
. **catch** ((err) => {
**let** errorMsg = err;
});
console.log(values);
});
}