I have two questions:
A. Can a user upload multiple images in a database and if yes how?
in my case i want the
user to be able to upload at least one or more images in the field “product images” by clicking the upload image button and selecting multiple images or/and by clicking the button and uploading one image at a time.
B. I want the images the user uploaded to be displayed in a gallery. I know that you can connect images to galleries but the images displayed will be one image from each row, i want for one row to link all the images e.g.
A) You can upload images and show on you gallery by getting the value uploaded, then inseerting it to your database, and lastly refreshing the gallery dataset. the following code is an example of how to do that:
B) you can do that using code by queering the collection, then pushing the image sources into an aray, and set the gallery items to that array. here’s a code example:
let galleryArr = []
wixData.query("myCollection")
.eq('title', 'gfbhf')
.find()
.then((results) => {
// get the item (row) and make an array
const items = results.items[0];
const objToArr = Object.values(items);
objToArr.forEach((link, i) => {
if (link === null) {
return;
} else if (link.toString().startsWith("image")) { // to only push images
galleryArr.push({ 'src': link });
}
});
$w('#gallery1').items = galleryArr
})
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
Hi Messa thanks your code almost worked! Just I’m in a item dynamic page and i want in .eq(‘title’, ‘name’) , name to be equal to the current item I’m viewing. Any ideas???
@johnfrantz17 There’s more than one way to get the value you are viewing it depends of how do you display different names?
One example would be if you have the value shown on a text box or a certain element, you get the value as follows: let name = $w(‘#element’).value , then u query based on this name.
Best Massa
Hello Massa I have applied your first code export function submitButton_click(event, $w) {… but each time I upload an image of the same item creates a new row in a database. The image is inserted in the media field but just one only. Something missing?
thank you
@massasalah18 Hello Massa I have applied your first code export function submitButton_click(event, $w) {… but each time I upload an image of the same item creates a new row in a database. The image is inserted in the media field but just one only. Something missing?thank you