Hi,
Is it possible to delete an image from a gallery by code? I've got a database with an embedded media gallery. I tried using wixData.remove but it doesn't seem to be deleting the image from the gallery. Please assist. Here's the code so far.
import wixData from 'wix-data';
$w.onReady( function() {
$w("#gallery1").onItemClicked((event)=>{
console.log("Gallery Item Title = "+ event.item.title);
console.log("Image file =" + event.item.src);
let image = event.item.title
let imagecover= event.item.src
const index = event.itemIndex;
console.log ("Gallery index=" + index)
$w('#input1').value=image
$w('#cover').src=imagecover
// then below i am placing that title into the #input1 box
})
})
// the user selects an image in the gallery below which is already connected to 'dynamicDataset and that image title is stored
export function text30_click(event) {
wixData.query("#dynamicDataset")
.find()
.then( (results) => {
if(results.items.length > 0) {
let firstItem = results.items[0];
wixData.remove("Gallery", firstItem)
.then(() => {
console.log ("item removed")
})
.catch((err) => {
let errorMsg = err;
});
}
//see item below
else {
// handle case where no matching items found
}
} )
.catch( (err) => {
let errorMsg = err;
})}
Greatly appreciate your assistance!
hello. I want to delete some of these photos on the update screen. Can you share the exact working code and settings?
Let's say you want to remove the first item in a media gallery filed.
Then:
//let's say the media gallery filed key is "images" //get the data record let's call it "item" item.images.shift(); // this line removes the first element from the array. wixData.update("CollectionName", item);