Question:
I have a collection with a Multi-Document field. I have a custom form with an upload button to upload up to 3 files. I have to use code to do the upload rather than connecting the field to a dataset because I also have an reCaptcha field on the form. The file is uploading to the site files but I cannot get it properly inserted into my collection multi-document field. Instead of seeing the file, I see a yellow triangle followed by all the file information.
Product:
Wix Studio Editor
What are you trying to achieve:
I want to allow the user to upload up to 3 documents and store them in a multi-document field in my collection.
What have you already tried:
I am doing the same thing with a Media Gallery field in the collection and it works fine. I tried to model the code for the multi-document field after the media gallery field and it is not working…yellow triangle.
Additional information:
pertinent code snippets:
$w("#uploadDocumentsButton").fileType = "Document"; // Site visitor can choose an document
console.log("just after filetype set to document")
if ($w("#uploadDocumentsButton").value.length > 0) { // Site visitor chose a file
console.log("Uploading the following documents:")
try {
const uploadedDocuments = await $w("#uploadDocumentsButton").uploadFiles();
for (let i = 0; i < uploadedDocuments.length; i++) {
const uploadedDocument = uploadedDocuments[i];
console.log("uploaded doc: " + uploadedDocument);
const documentItem = {
type: "document",
title: uploadedDocument.originalFileName,
src: uploadedDocument.fileUrl,
description: uploadedDocument.originalFileName
}
console.log("document item:", documentItem);
myDocuments.push(documentItem);
}
console.log("upload of documents successful");
} catch (error) {
console.log("Document upload error: " + error.errorCode);
console.log(error.errorDescription);
}
}
submitForm();
async function submitForm() {
let submitRequestData = {
“token”: $w(“#captcha1”).token,
“data”: {
“requestType”: ‘Loan’,
“firstName”: $w(‘#inputFirstName’).value,
“lastName”: $w(‘#inputLastName’).value,
“emailAddress”: $w(‘#inputEmailAddress’).value,
“phone”: $w(‘#inputPhone’).value,
“zipCode”: Number($w(‘#inputZipCode’).value),
“assetType”: $w(‘#dropdownAssetType’).value,
“assetDescription”: $w(‘#inputAssetDescription’).value,
“requestedLoanAmount”: Number($w(‘#inputRequestedLoanAmt’).value),
“originalPurchasePrice”: Number($w(‘#inputOriginalPurchasePrice’).value),
“dateOfOriginalPurchase”: $w(‘#datePickerOriginalPurchaseDate’).value,
“photos”: myImages,
“documents”: myDocuments,
“additionalInfo”: $w(‘#textBoxAdditionalInfo’).value
}
}