So I’m using code to inject all inputs into a collection, and I have an Upload button that allows users to upload documents. However, in the inject, I entered upload: $w( ‘#upload’ ).value, which rather than storing the document itself in the collection, it just stores the name. How do I store the document itself in the collection? I saw startUpload( ) on the API, but my issue is that i need to be able to inject this outside the .then function because I have a lot of other stuff to inject to the collection.
Here is my code:
import wixData from ‘wix-data’ ;
import wixUsers from ‘wix-users’ ;
import wixWindow from ‘wix-window’ ;
import { doRegistration } from ‘backend/register’ ;
let user = wixUsers.currentUser;
let isUserLoggedIn = user.loggedIn;
$w.onReady(( function () {
if (isUserLoggedIn) {
$w( “#password” ).collapse();
$w( “#title” ).text = “Sign NDA” ;
user.getEmail()
.then((email) => {
$w( “#email” ).value = email;
});
}
}));
function validateRequiredFields(fieldKeys) {
let validationPassed = true ;
fieldKeys.forEach(fieldKey => {
let field = $w( ‘#’ + fieldKey);
if (field.validity.valueMissing) {
field.updateValidityIndication();
validationPassed = false ;
}
});
return validationPassed;
}
function clearFields(fieldKeys) {
fieldKeys.forEach(fieldKey => {
let field = $w( ‘#’ + fieldKey);
if (field.type === ‘$w.SignatureInput’ ) {
field.clear();
} else {
field.value = null ;
}
if (field.validity.valueMissing) {
field.resetValidityIndication();
}
});
}
export function signupButton_click(event) {
let termsIsChecked = $w( “#acceptTerms” ).checked;
let OpportinitiesIsChecked = $w( “#futureOpportunities” ).checked;
if ($w( “#futureOpportunities” ).checked) {
$w( “#futureOpportunities” ).value = “Yes” ;
} else {
$w( “#futureOpportunities” ).value = “No” ;
}
const item = {
firstName: $w( ‘#firstName’ ).value,
lastName: $w( ‘#lastName’ ).value,
email: $w( ‘#email’ ).value,
company: $w( ‘#company’ ).value,
position: $w( ‘#position’ ).value,
date: $w( ‘#date’ ).value,
upload: $w( ‘#upload’ ).value,
url: $w( ‘#url’ ).value,
phone: $w( ‘#phone’ ).value,
acceptTerms: $w( ‘#acceptTerms’ ).value,
futureOpportunities: $w( ‘#futureOpportunities’ ).value,
signature: $w( ‘#signature’ ).value
}
const keys = Object.keys(item);
if (validateRequiredFields(keys)) {
wixData.insert( ‘nda’ , item)
.then((results) => {
$w( ‘#successMessage’ ).show();
$w( ‘#validationMessage’ ).hide();
clearFields(keys);
})
. catch ((error) => {
console.log(error);
});
} else {
$w( ‘#validationMessage’ ).show();
}
if (isUserLoggedIn) {} else {
let firstName = $w( “#firstName” ).value
let lastName = $w( “#lastName” ).value
let company = $w( “#company” ).value
let email = $w( “#email” ).value
let password = $w( “#password” ).value
let position = $w( “#position” ).value
let phone = $w( “#phone” ).value;
doRegistration(email, password, firstName, lastName, company, position, phone)
.then((result) => {
let userId = result.user.id
let userInput = {
“firstName” : firstName,
“lastName” : lastName,
“company” : company,
“email” : email,
“position” : position,
“phone” : phone,
“_id” : userId
}
wixWindow.openLightbox( “Confirm your email” )
});
}
}
export function signature_change(event) {
$w( ‘#validationMessage’ ).hide();
$w( ‘#successMessage’ ).hide()
}