Delete Pic in Temporary Gallery (pre-form submit)

Hi guys

Have already:
I have my code to upload multiple images to a temporary gallery (from a single upload button) for people to preview before they submit the images to a gallery.

Need:
I’m trying to add an “image delete button” to remove the current image being viewed in the Temporary Gallery.

Something like:

export function imagedeletebutton_click(event, $w) {
let currentIndex = $w("#gallery1").currentIndex;
let item = $w("#gallery1").items[currentIndex].src;
item.remove();
} 

Does anyone have any ideas?

Many thanks!

Thomas

Did you try getting the items , removing one from the array and then setting the items back on the gallery?

Hi Dalia

Many thanks for the response. Sorry, I’ve been away this month so I haven’t been very active with the forum.

I decided a different approach would be easier. I’ve changed it to a repeater, put the image as the whole repeater and am filtering results from a dataset on the page instead. (it’s filtered via a g.u.i.d code generated on the page).

This is what it looks like:

However, I’m trying to make the little “X” button on the repeater delete the item in the dataset, but i’m struggling.

This is my code to date, but it’s not responding:

export function iconButton1_click(event, $w) {
	
		let item = $w("#dataset1").getCurrentItem();
		let title = $w("#text153").text; // key generated as page loads
		wixData.remove("images", item)
	
		$w("#dataset1").onReady( () => {

			$w("#dataset1").setFilter(wixData.filter().eq("title", title)); // should filter dataset to match text153
						
		})
}

Any idea on how to action this to delete the current item on the dataset?

Many thanks for the help to date!

Thomas

Hi Thomas
The remove functions needs the id as parameter : wix-data - Velo API Reference - Wix.com

I suggest writing something like this :
wixData.remove(“images”, item._id)
.then(() => {
//refresh the repeater with the updated info
$w(’ #r epeater1’).refresh();
}) .catch((err) => {
let errorMsg = err;
});

Hi Dalia

Thanks! It worked perfectly :slight_smile:

However, the repeater isn’t refreshing as expected. It says “it does not exist on the repeater”

Many thanks

Thomas

Hi Thomas
It turns out there is a much easier way that will also refresh your repeater:
export function iconButton1_click(event, $w) {
$w(“#dataset1”).remove()
.then( () => {
console.log(“Done removing current item”);
} );
}
I hope that works better :slight_smile:

Works perfectly!

Many thanks for your help, Dalia :slight_smile:

Hi Thomas,

You said in your OP that you have code already to push images to a temporary gallery. Would you be able to share that? That is exactly what I am trying to do, and I’ve been running into issues.