I have a list called Tenders. I need to make sure that when Tender status field is set to "open" no one can delete it. Ideally would be if I won't see options in ecb and ribbon. It is not connected to users permissions but with state of list item. Should I use jQuery or is there an easier way?
4 Answers
Could you check this post for some help? - http://pholpar.wordpress.com/2011/10/16/disabling-item-deletion-at-the-sharepoint-user-interface/
You could create an Event Receiver for the OnDeleting event that prevents the item from being deleted. Basically have the event receiver check for the value of the field and cancel deletion if the right requirements are not met.
-
ItemDeleting is the name of the event receiver: msdn.microsoft.com/en-us/library/…John Chapman– John Chapman2011-12-09 17:53:08 +00:00Commented Dec 9, 2011 at 17:53
-
Yes, I know but it is the server side, but how to prevent it on the client side. Simply hide the buttons. I have an idea to work with live() function in jquery and checking the values of current row - status is there, but that is quite tricky.christof– christof2011-12-09 19:53:13 +00:00Commented Dec 9, 2011 at 19:53
It would be much better UX IMO to prevent the delete by either removing all the delete buttons or disabling them. Telling the user that they can't delete something after a post back is generally considered annoying these days.
Using client side script means that your user can always hack the page, of course, and delete the item anyway. It all comes down to your business requirements.
A very much easier approach is to use a conditional show/hide action on Delete button on the JSON of the view:
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
"commandBarProps": {
"commands": [
{
"key": "delete",
"hide": "=if([$Tenders]=='open',true,false)"
}
]
}
}
Best reggards,
Juan.