Delete Item from Collection using dropdown

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];

  wixData.remove("Properties",  firstItem._id); 
  }  **else**  { 

// handle case where no matching items found
}
} )
. catch ( (err) => {
let errorMsg = err;
} );
}

Thanks again in advance for any help!

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.

Thanks for your reply J.D.

I think it’s finding the record OK because just prior to this code I display the record that is to be deleted…

@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.

Thanks again.

Hi Steve,

cheeky question but as you know what you are doing, is there any chance you could have a look at my forum post

refresh image after upload

its a real sticking point for progress

Thanks and Regards
Adam