Remove Function

Hi Corvid Pros,

I have recently landed a client and have had to learn how to use Wix Code without any background in coding at all within a month. I have successfully done what was required for the task however there are a free rough edges here and there.

The functionality of the site is simple; User Signs Up, they add things to their ‘product queue’ and then sign up for a monthly subscription and receive the products in their queue monthly.

The issue has been that the remove function connected to the items within the repeater on the product queue, works only sometimes. For example, when I test it on the live site both desktop and mobile, it works fine. However when my client has tried to use the remove function button, it doesn’t work. For my girlfriend it worked on her phone not on her desktop and some customers are also contacting us with the same issue.

Another issue also related to the same repeater after remove function DOES want to work is that it removes selected item from the database and then only occasionally will then show all the items from the database on the repeater and not just the items from the current user. I have had to do a query after the remove function code, however it only works sometimes.

The code is:

export async function removeitem_click_1(event) {
let $item = $w.at(event.context);
await $item(‘#myscents’).remove(event);
wixData.query(“MyScents”)
.limit(12)
.ascending(“_createdDate”)
.eq(“_owner”, userID)
.find()
.then((results) => {
$w(“#Wishlist”).data = results.items;
});
}


Full Page Code is:

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixWindow from ‘wix-window’;
import wixLocation from ‘wix-location’;
let user = wixUsers.currentUser;
let userID = user.id;
let itemObj;
var useremail
var productimage
var productname
var productbrand
var producturl
var productplan
$w.onReady( function () {
user.getPricingPlans()
.then((plans) => {
plans.forEach((plan) => {
let planName = plan.name;
console.log(planName);
if (planName === “Monthly”) {
$w(“#button26”).collapse();
} else if (planName === “Practice”) {
$w(“#button26”).collapse();
} else if (planName === “Premium”) {
$w(“#button26”).collapse();
}
});
});
$w(“#Wishlist”).onItemReady(($item, itemData, index) => {
$item(“#productimage”).src = itemData.productimage;
});
$w(“#repeater1”).onItemReady(($item, itemData, index) => {})
$w(“#myscents”).onReady(($item, itemData, index) => {
wixData.query(“MyScents”)
.limit(12)
.ascending(“_createdDate”)
.eq(“_owner”, userID)
.find()
.then((results) => {
$w(“#Wishlist”).data = results.items;
});
})
user.getEmail()
.then((email) => {
let userEmail = email;
$w(‘#text109’).text = userEmail;
useremail = $w(‘#text109’).text;
});
});
export function button26_click(event) {
let isLoggedIn = user.loggedIn;
if (!isLoggedIn) {
wixLocation.to(“https://www.scentmecca.com.au/choose-your-atomiser”)
} else {
wixUsers.promptLogin()
wixLocation.to(“https://www.scentmecca.com.au/choose-your-atomiser”)
}
}
export async function removeitem_click_1(event) {
let $item = $w.at(event.context);
await $item(‘#myscents’).remove(event);
wixData.query(“MyScents”)
.limit(12)
.ascending(“_createdDate”)
.eq(“_owner”, userID)
.find()
.then((results) => {
$w(“#Wishlist”).data = results.items;
});
}
export function button27_click(event) {
if (wixUsers.currentUser.loggedIn) {
addproduct(event);
let $item = $w.at(event.context);
$item(“#added”).show();
} else {
wixUsers.promptLogin()
}
}
function addproduct(event) {
let $item = $w.at(event.context);
let clickedItemData = $item(“#dataset1”).getCurrentItem();
let productimage = clickedItemData.mainMedia;
let productname = clickedItemData.name;
let productbrand = clickedItemData.brand;
let producturl = clickedItemData.memberItemsBrandName;
let productplan = clickedItemData.plan;
let userId = user.id;
wixData.query(“MyScents”)
.eq(“name”, productname)
.eq(“_owner”, userID)
.find()
.then((results) => {
let items = results.items;
let firstItem = items[0];
let count = results.totalCount;
if (count === 0) {
let toSave = {
“productimage”: productimage,
“name”: productname,
“productbrand”: productbrand,
“producturl”: producturl,
“useremail”: useremail,
“plan”: productplan
};
wixData.save(“MyScents”, toSave)
.then((results) => {
let item = results; //see item below
})
. catch ((err) => {
let errorMsg = err;
});
} else wixWindow.openLightbox(“mixitup”);
})
}

Thank you for your time reading and responding!
Cheers

One thing you should be aware of is that you will need to clear your repeater before you assign the new filtered results. You can do this:

$w("#Wishlist").data = [];
$w("#Wishlist").data = results.items;

What this does is trigger the onItemReady() function to “start all over again” so that the existing items in the repeater don’t conflict with the new data.

Thank you Yisrael! Where would I place that piece of code?

Right after remove(event) in the remove item onclick function?

@dylan16870 Put it in the same place you have it now. Just add this line first:

$w("#Wishlist").data = [];

@yisrael-wix okay thank you! I will give it a try!

do you have any thoughts on why the remove function only works sometimes for some users?

Hi @yisrael-wix , I included the code you suggested, however on mobile it doesnt seem to want to work, any thoughts on this?

Please post the URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.