Delete button to delete collection data externally

There is the delete option in the “Link connects to…” when connecting a button to a dataset, but how do I configure it so members-only can choose what to delete, and use the delete button?

Optional: Is there a way to also update/modify database data externally for members?

Thank you very much for your time.

1 Like

Following

If by ‘What to delete’, you’re referring to a specific field in the Database, then you can achieve that by adding input components (text/dropdown/radio buttons/ checkboxes) and writing some code.

You’ll need to create your own Delete button and implement an onClick function for it.
Inside this function, read the input field (e.d. dropdown ), then use wixData module to read and update fields.

Liran.

That’s exactly what I meant, thanks a lot!

The only problem is that I forgot to state I have no basis (yet, I only know C++) in Javascript so I’m not really sure what to use with these functions, especially about reading the input field of a dropdown menu, for the Delete button.

Hi,

There’s no way of avoiding code here, but I’ll help you get started (since you’re familiar with C++, I think it will be pretty clear to you).
Let’s break it down a bit.
first of all, you only want to allow members to delete, so I’ll go with setting the button and drop down to be hidden on load (in the properties panel), and then show them if needed when the page is ready:

import wixUsers from 'wix-users';
$w.onReady(fucntion(){
    const currentUser = wixUsers.currentUser;
    if (currentUser.loggedIn && user.role === 'Member') {
        //show relevant components here...
    }
});

Use this as a template, please read comments:

import wixData from 'wix-data';
export function button1_click() {
    const valueToRemove = $w('#dropDown1').value;
    const currentUser = wixUsers.currentUser; 
    if (currentUser.loggedIn) { 
         currentUser.getEmail().then(email => {
             //use wixData.query() to get the relevant info
             // and then use wixData.update() to update it
             // (see previous links that I've provided)
         })
    }
}

Liran.