I have two fields Lat Name, First Name fields and an Image Upload button. Also I would like to add few more fields but before I want these name fields and Image successfully saved into database collection. I would like to validate the name fields in a different function before inserting into db. But the button1_click event does not save the image to the database. only name fields are saved. The code I have used is below. Also the screen image. Can anyone help on fixing this problem?
export function ChefDB_beforeInsert(item, context) {
let toUpdate = {
chefnamelast:toUpperFirst($w(‘#input1’).value),
chefnamefirst:toUpperFirst($w(‘#input2’).value),
chefimage:image_load ()
//chefimage:$w(‘#uploadButton1’).value
};
wixData.insert(“Chef”, toUpdate)
.then( (results) => {
let item1 = results; //see item below
console.log(“Item:”, item1)
} )
. catch ( (err) => {
let errorMsg = err;
} );
}
function toUpperFirst(s) {
let ch1 = s.charAt(0).toUpperCase() + s.slice(1);
console.log(ch1);
return ch1;
}
export function button1_click(event, $w) {
ChefDB_beforeInsert();
}
export function image_load () {
if ($w(“#uploadButton1”).value.length > 0) { // user chose a file
console.log(Uploading '${$w("#uploadButton1").value[0].name}');
$w("#uploadButton1").startUpload()
.then( (uploadedFile) => {
console.log("Upload successful. File is available here:");
console.log(uploadedFile.url);
} )
. **catch** ( (uploadError) => {
console.log(`File upload error: ${uploadError.errorCode}`);
console.log(uploadError.errorDescription);
} );
}
else { // user clicked button but didn’t chose a file
console.log(“Please choose a file to upload.”)
}
}
