So I’m afraid I’m here again asking help for something that must be obvious but I cannot work it out!
I have a database of properties. Numerous properties can belong to one user. I want this user to be able to select a specific property from a dropdown list and then delete it. I have the dropdown list working, displaying all the relevant properties but when I come to delete the item it always deletes the first item in the database. Not the one selected.
Here’s my attempt:
export function button5_click_1(event) {
wixData.query(“Properties”)
.eq(“propertyName”, $w(“#dropdown1”).value)
.find()
.then( (results) => { if (results.items.length > 0) { let firstItem = results.items[0];
Your code looks fine.
I’d guess that the value in the dropdown is undefined, and that’s why it retrieves the first 50 items from the database and remove the first one.
Try to log the value from the dropdown to the console and see what it is.
@stevebarton998 If it’s still not working, I suggest you’ll add some console.log() with the dropdown value, the query results and the removal results in order to locate the problem.
@jonatandor35 Thanks again for your help. I worked out the issue - silly mistake on my behalf. I had linked the button that I was using to the delete to ‘delete’ and I think this was overriding my code. Once I removed the link it worked.