1. Using a form I get user inputs (text) and a document file (by upload button) and insert both texts and files into different fields of a collection by submit button.
2. Using another page (an update page), I querry the collection and display fields of the collection filtering by one of the fields (using dropdown menu). There is also an upload button on page because user prefers updating the document inserted in the first place.
The problem arises here. I cannot assign newly updated document to the relevant field of the collection. Using submit button is useless on that page so I use wixData.update to submit the updated fields.
For example, I thought the below codes could work. Bu it didn't. Probably stg wrong with the bold lines. Do you have idea to overcome this issue?
let document = 'mydocument';
export function uploadButton1_click(event) { $w("#uploadButton1").startUpload() .then( (uploadedFile) => { document.doc = uploadedFile.url; }) }
let Update = { "_id": $w('#input1').value, "name": $w('#txtbox2').value, "description": $w('#txtbox3').value, "document": document.url };
wixData.update("customers", Update) .then( (results) => { let item = results; //see item below } ) .catch( (err) => { let errorMsg = err; } ); }
Thanks,
Glad that you got it working!
Good job!
Roi.
Roi hi,
Your latest comments were very helpful.I used an extra button for uploading the file as it is explained in the article https://support.wix.com/en/article/how-to-use-the-upload-button-with-code#wire-upload-code . And used another button for submitting to collection. The below code line was ok for submitting document to related field in the colection.
"document": $w("#image1").link
Thank you very much.
Hi,
I looked at your code. You set two actions for one button (onclick and connect to dataset). It causes unstable behaviour.
First follow these articles before making changes.
https://support.wix.com/en/article/how-to-use-the-upload-button-with-code#wire-upload-code
Make sure you set one action for each button.
Roi.
Sorry I forgot to write. "Açık Pozisyon Güncelleme".
What is the name of the page?
Roi.
Roi hi. As I am in the process of learning code can be a little bittle raw and some pages are not ready.
https://editor.wix.com/html/editor/web/renderer/edit/dd880746-12c6-45fb-8d2a-3d1020ad2efb?metaSiteId=8f0c1cf5-5f79-41a6-b69f-c0f436074aac&editorSessionId=DD05555E-4E16-49C9-8E4E-AD52AAF6C793&referralInfo=my-account
Thanks,
Can you please share a link to your site and specify the name of the page so we can give you accurate answers?
Roi.
Hello Roi. Thanks for reply. I applied changes you recommended but it is still like below on the collection. My field type is document. I think the problem is still that: I am trying to save an image to a document type field in the collection.
And the code is as follows:
export async function uploadButton1_change (event, $w) { const uploadedFile = await $w("#uploadButton1").startUpload(); $w("#image1").src = uploadedFile.url; } export function button1_click(event, $w) { let toUpdate = { "_id": $w('#input1').value,
"name": $w('#txtbox2').value,
"description": $w('#txtbox3').value, "document": $w("#image1").src }; wixData.update("customers", toUpdate) .then( (results) => { let item = results; //see item below } ) .catch( (err) => { let errorMsg = err; } ); }
I also tried to use a document item but this time I cannot pass uploadedFile.url to a document item like below.
export async function uploadButton1_change (event, $w) { const uploadedFile = await $w("#uploadButton1").startUpload(); $w("#document1").xxx = uploadedFile.url; } export function button1_click(event, $w) { let toUpdate = { "_id": $w('#input1').value,
"name": $w('#txtbox2').value,
"description": $w('#txtbox3').value, "document": $w("#document1").xxx };
Roi, actually I am wondering the code WIX itself uses to save an uploaded document to a collection in the first place. We can do this as a given functionality, but the code behind it could be the answer to this issue. What do you think?
Thanks,
Hi,
You are trying to make async actions with regular sync syntax.
For example, the update method triggered before it finishes to upload the image. Therefore the field is empty in the DB.
Check out Async/await article.
Roi.
Andreas thanks for reply.
It didn't work unfortunately. I see the new document uploadaed. But when it sends to collection, the new document is not sent and old one is deleted. Actually if it was a an image I was trying to replace, the code below could work i think. I took it from this article: https://support.wix.com/en/article/how-to-use-the-upload-button-with-code
$w("#uploadButton1").startUpload()
.then( (uploadedFile) => {
$w("#text1").text = "Upload successful";
$w("#image1").src = uploadedFile.url;
})
But as it is a document I am trying to replace; what should use instead of $w("#image1").src ?
Do you have an idea?
Thanks,
document.doc = uploadedFile.url; should be document = uploadedFile.url;