@jonatandor35 hello, how i said it all working!! thnaks again.
I have to added now another uploadbuttun “#uploadbutton2” to send one image ( like main image ) to my image field database.
could you help where and howshould i write the code here are my final code that works well excepeted sending image to uploadbutton2 to image field.
import wixUsers from “wix-users”;
import wixData from “wix-data”;
import wixLocation from ‘wix-location’;
let userId = wixUsers.currentUser.id;
let galleryItems = [];
let toSave = {userId: userId, album: []};
$w.onReady( function () {
$w(“#uploadButton1”).fileType = “Image”;
$w(“#uploadButton1”).onChange( () => {
if ($w(“#uploadButton1”).value.length > 0) {
$w(“#submit”).disable();
$w(“#uploadButton1”).buttonLabel = “Loading…”;
$w(“#uploadButton1”).startUpload()
.then( (uploadedFile) => {
galleryItems.push({type: “image”, src: uploadedFile.url});
$w(“#gallery1”).items = galleryItems;
$w(“#gallery1”).expand();
toSave.album.push({“type”: “image”, “src”: uploadedFile.url});
$w(“#submit”).enable();
toSave.album.length > 1 ? $w(“#submit”).label = “Save Images” : $w(“#submit”).label = “Save Image”;
$w(“#uploadButton1”).buttonLabel = “Add another image”;
$w(“#uploadButton1”).reset();
} )
. catch ( (uploadError) => {
console.log(File upload error: ${uploadError.errorCode}
);
console.log(uploadError.errorDescription);
} );
}
} );
let userInputs = [ $w(“#dropdown1”), $w(“#dropdown2”), $w(“#dropdown3”), $w(“#dropdown4”), $w(“#input1”), $w(“#input2”), $w(“#input5”), $w(“#input6”), $w(“#input7”), $w(“#checkboxGroup1”), $w(“#checkboxGroup2”), $w(“#checkboxGroup3”), $w(“#checkboxGroup4”), $w(“#textBox1”), $w(“#uploadButton2”), ];
userInputs.forEach(e => {
e.onChange(event => {
userInputs.every(i => i.valid) ? $w(“#submit”).enable() :$w(“#submit”).disable();
// Possivel codigo!!!
//let fileType = $w(“#uploadButton2”).fileType; // “Image”
//$w(“#uploadButton2”).fileType = “image”;
})
})
$w(“#submit”).onClick((event) => {
toSave.title = $w(“#input1”).value;
toSave.year = $w(“#input2”).value;
toSave.beam = $w(“#input5”).value;
toSave.halfTime = $w(“#input6”).value;
toSave.fullTime = $w(“#input7”).value;
toSave.listedFor = $w(“#dropdown1”).value;
toSave.cabins = $w(“#dropdown2”).value;
toSave.toilets = $w(“#dropdown3”).value;
toSave.guests = $w(“#dropdown4”).value;
toSave.features = $w(“#checkboxGroup1”).value;
toSave.features2 = $w(“#checkboxGroup2”).value;
toSave.features3 = $w(“#checkboxGroup3”).value;
toSave.features4 = $w(“#checkboxGroup4”).value;
toSave.about = $w(“#textBox1”).value;
toSave.photo = $w(“#uploadButton2”).value; // dosent send the image to image field collection
$w(“#submit”).label = “saving…”;
$w(“#uploadButton1”).disable();
$w(“#submit”).disable();
wixData.save(“EstoqueMiami”, toSave)
.then(() => {
$w(‘#input1’).value = “”;
$w(‘#input2’).value = “”;
$w(‘#input5’).value = “”;
$w(‘#input6’).value = “”;
$w(‘#input7’).value = “”;
$w(‘#dropdown1’).value = “”;
$w(‘#dropdown2’).value = “”;
$w(‘#dropdown3’).value = “”;
$w(‘#dropdown4’).value = “”;
$w(‘#checkboxGroup1’).value = “”;
$w(‘#checkboxGroup2’).value = “”;
$w(‘#checkboxGroup3’).value = “”;
$w(‘#checkboxGroup4’).value = “”;
$w(‘#textBox1’).value = “”;
$w(“#submit”).label = “✓ Saved”;
$w(“#submit”).disable();
$w(“#gallery1”).items = [];
$w(“#gallery1”).collapse();
galleryItems = [];
toSave = {userId: userId, album: []};
$w(“#uploadButton1”).buttonLabel = “Add an Image”;
$w(“#uploadButton1”).enable();
})
})
})