User multi-upload // image & video user-upload shown in a gallery

I’m not having much luck with onitemclick, am I missing out on something?

I’ve seen this but not sure what I need to replace it with…

$w(“#myGallery”).onItemClicked( (event) => {
let itemDescription = event.item.description; // “Description”
let itemIndex = event.itemIndex; // 3
} );


import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
let result = [];
let value = [];

export function uploadButton1_change(event) { //image upload button
 if ($w("#uploadButton1").value.length > 0) {
        $w("#uploadButton1").buttonLabel = "Uploading"
        $w("#uploadButton1").disable();
        $w("#uploadButton2").disable();
        $w('#uploadButton1').startUpload()
            .then((uploadedFile) => {
                value.push({ "slug": "Title", "src": uploadedFile.url, "title": "title", "type": "image" });
                $w("#uploadButton1").buttonLabel = "Upload again"
                $w("#uploadStatusText").show();
                $w("#uploadStatusText").text = "Upload Successful"
                $w("#uploadButton1").enable();
                $w('#uploadButton2').enable();
                $w('#uploadButton1').reset();
                $w('#dataset25').refresh();
                $w('#gallery').show();
                $w('#gallery').items = value;
                $w('#imagedeletebutton').show();
                $w("#save").enable();
                console.log(value);
            })
    }
}

export function uploadButton2_change(event) {
 if ($w("#uploadButton2").value.length > 0) {
        $w("#uploadButton2").buttonLabel = "Uploading"
        $w("#uploadButton2").disable();
        $w("#uploadButton1").disable();
        $w('#uploadButton2').startUpload()
            .then((uploadedFile) => {
                value.push({ "slug": "Title", "src": uploadedFile.url, "title": "title", "type": "video" });
                $w("#uploadButton2").buttonLabel = "Upload again"
                $w("#uploadStatusText").show();
                $w("#uploadStatusText").text = "Upload Successful"
                $w('#gallery').items = value;
                $w('#uploadButton2').reset();
                $w('#uploadButton2').enable();
                $w('#uploadButton1').enable();
                $w('#dataset25').refresh();
                $w('#gallery').show();
                $w('#imagedeletebutton').show();
                console.log(value);
            })
    }
}

export function gallery_itemClicked(event) {
 let indexNum = event.itemIndex;
 let i = indexNum
    value = value.slice(0, i).concat(value.slice(i + 1, value.length))
    $w('#gallery').items = value;
}

export function save_click(event) {
    $w("#save").label = "Publishing..."
    $w("#save").disable();
    $w('#uploadButton1').disable();
    $w('#uploadButton2').disable();
 let toInsert = {
 "gallery": value
    };

    wixData.insert("marks", toInsert) //database name
        .then((results) => {
            $w("#save").label = "Published"
            $w("#save").enable();
            $w('#uploadButton1').enable();
            $w('#uploadButton2').enable();
            $w("#dataset25").refresh();
        })
}

In your this code →

$w(" #myGallery ").onItemClicked( (event) => {
let itemDescription = event.item.description; // “Description”
let itemIndex = event.itemIndex; // 3
} );

Change the “myGallery” to your gallery’s id (which can be seen in the properties panel…)

And for your code here →

export function gallery_itemClicked(event) {
 let indexNum = event.itemIndex;
 let i = indexNum
    value = value.slice(0, i).concat(value.slice(i + 1, value.length))
    $w('#gallery').items = value;
}

Delete this part and paste the below code under the onReady…

 $w('#gallery1').onItemClicked((event) => {
        let indexNum = event.itemIndex;
 let i = indexNum
        value = value.slice(0, i).concat(value.slice(i + 1, value.length))
        $w('#gallery1').items = value;

    });

Something like this →

import wixData from 'wix-data';
import wixUsers from 'wix-users';
import wixLocation from 'wix-location';
import wixWindow from 'wix-window';
let result = [];
let value = [];

$w.onReady(function () {
  $w('#gallery1').onItemClicked((event) => {      //gallery
        let indexNum = event.itemIndex;
 let i = indexNum
        value = value.slice(0, i).concat(value.slice(i + 1, value.length))
        $w('#gallery1').items = value;

    });

});
export function uploadButton1_change(event) { //image upload button
 if ($w("#uploadButton1").value.length > 0) {
        $w("#uploadButton1").buttonLabel = "Uploading"
        $w("#uploadButton1").disable();
        $w("#uploadButton2").disable();
        $w('#uploadButton1').startUpload()
            .then((uploadedFile) => {
                value.push({ "slug": "Title", "src": uploadedFile.url, "title": "title", "type": "image" });
                $w("#uploadButton1").buttonLabel = "Upload again"
                $w("#uploadStatusText").show();
                $w("#uploadStatusText").text = "Upload Successful"
                $w("#uploadButton1").enable();
                $w('#uploadButton2').enable();
                $w('#uploadButton1').reset();
                $w('#dataset25').refresh();
                $w('#gallery').show();
                $w('#gallery').items = value;
                $w('#imagedeletebutton').show();
                $w("#save").enable();
                console.log(value);
            })
    }
}

export function uploadButton2_change(event) {
 if ($w("#uploadButton2").value.length > 0) {
        $w("#uploadButton2").buttonLabel = "Uploading"
        $w("#uploadButton2").disable();
        $w("#uploadButton1").disable();
        $w('#uploadButton2').startUpload()
            .then((uploadedFile) => {
                value.push({ "slug": "Title", "src": uploadedFile.url, "title": "title", "type": "video" });
                $w("#uploadButton2").buttonLabel = "Upload again"
                $w("#uploadStatusText").show();
                $w("#uploadStatusText").text = "Upload Successful"
                $w('#gallery').items = value;
                $w('#uploadButton2').reset();
                $w('#uploadButton2').enable();
                $w('#uploadButton1').enable();
                $w('#dataset25').refresh();
                $w('#gallery').show();
                $w('#imagedeletebutton').show();
                console.log(value);
            })
    }
}



export function save_click(event) {
    $w("#save").label = "Publishing..."
    $w("#save").disable();
    $w('#uploadButton1').disable();
    $w('#uploadButton2').disable();
 let toInsert = {
 "gallery": value
    };

    wixData.insert("marks", toInsert) //database name
        .then((results) => {
            $w("#save").label = "Published"
            $w("#save").enable();
            $w('#uploadButton1').enable();
            $w('#uploadButton2').enable();
            $w("#dataset25").refresh();
        })
}

And for your " If user uploads one image, image is saved in ‘markcoverPhoto’ and ‘gallery’ field in ‘marks’ collection? I’ve been playing around with the codes with no success!’ post?" … you should indeed create a new post…
:wink:

@ajithkrr OK so this works!

The issue I’m still having it that I have other things to save so I’m trying to combine your SAVE code with mine?

export function SubmitCreate_click(event) {
    $w("#SubmitCreate").label = "Publishing..."
    $w("#SubmitCreate").disable();
    $w("#dropPublish").disable();
    $w("#dropCreateanother").disable();
    $w("#previewButton").disable();
    $w("#MarksDataset").save().then((item) => {
        wixData.insertReference("marks", "mymarks", item._id, result.items[0]._id)
        wixData.query("marks")
            .eq("_id", wixData._id)
            .find()
            .then((res) => {
 let headline = res.items[0].headline.split(' ').join('-');
 let id = res.items[0]._id;
 let category = res.items[0].category;
                id = id.split(':').join('%3A');
                category = category.split(':').join('%3A');
                headline = headline.split(' ').join('-');
                wixLocation.to(`/marks/${id}/${category}/${headline}`)
            })
            .catch((err) => {
 let errorMsg = err;
            })
    })
}

Hey mate, wondered if you could had any luck with this? I’ve been trying and it’s driving me insane!

I think you should certainly create a new post