I have a collection named “Prospects” where anyone can access, view and delete content…connected to #dataset2 named “Prospects dataset” and one of the fields in the collection is “Full Name” with the field key “name”. Each member currently has (read & write) access to view their prospects through a table named #table1. I would like the members to be able to delete prospects from the collection through the use of a dropdown named #dropdownName and then submit the change with a button named #btnDelete and show a success/error message #txtMessage. Can someone please help me figure out where I am going wrong??? I not an expert coder by any means but I’m usually pretty ok following directions and duplicating those instructions. I got this code from another page with an example of it working and I thought I copied and changed everything correctly but when I run it my error message shows and nothing is deleted. Thanks ahead of time!
HERE’S THE CODE…
import wixData from ‘wix-data’ ;
export function dropdownName_change ( event ) { if ( $w ( “#dropdownName” ). value !== ‘’ ) {
$w ( “#btnDelete” ). enable ();
}
}
export function btnDelete_click ( event ) {
wixData . query ( “Prospects” )
. eq ( “name” , $w ( “#dropdownName” ). value )
. limit ( 1000 )
. find ()
. then (( result ) => { let x = 0 ; for ( var i = 0 ; i < result . items . length ; i ++) { if ( result . items [ i ] === null ) continue ;
wixData . remove ( “Prospects” , result . items [ i ]. _id )
. then (() => {
x ++; if ( result . items . length === x ) {
$w ( “#txtMessage” ). text = $w ( “#dropdownName” ). value +
" has been deleted from this collection." ;
refreshRepeater ()
}
});
}
})
. catch (( err ) => {
console . log ( err );
$w ( “#txtMessage” ). text = “An unexpected error has occurred.” ;
});
}
If no one can help me correct this, can someone please lead me in the direction to the page that shows how to get the delete function without code in the “connect to data” to work correctly? I even tried using that and it only deletes whatever value is at the top of the list and not the value I choose.
@texasbillionairesclu you should check the collection permissions. Make sure there’s a permission to delete from this collection.
You should log error to the console and to the site monitoring tool to locate the problem.