Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have made a custom sharepoint site, where i have disabled the remove button from the ribbon and the context menu. But i just found out that then if I select an item in a document library, i can still press the delete key on the keybord and it will delete the item from the document library i will like to disable the delete key on the keyboard on the sharepoint site; how can this be done ?

share|improve this question
add comment

2 Answers 2

yes you can but from the top of my head using javascript and cewp would be a simple solution.

add this in the cewp:

$('html').bind('keypress', function(e) 
{ 
   if(e.keyCode == 46) 
   { 
      return false; 
   } 
}); 

taken from here:

http://stackoverflow.com/questions/1235716/disable-keyboard-enter-key

i just added the right keycode in for you :) , you would obviusly need to put the cewp on the document library page ;)

EDIT

Ok just relised the code above wont work as it would be listing for an input so Iv dont the code for you! Its simple really and doesnt require you to assign the function to a input box or such, it check to see if your in a textbox and if you are then delete button works as normal otherwise its disabled :)

<script type="text/javascript" language="javascript">  
$(document).keydown(function(e) {
var element = e.target.nodeName.toLowerCase();
if (element != 'input' && element != 'textarea') {
    if (e.keyCode === 46) {
        return false;
    }
}
});
</script> 

If you dont want that feature and want to disable it all together than add the following:

<script type="text/javascript" language="javascript">  
$(document).keydown(function(e) {
var element = e.target.nodeName.toLowerCase();
    if (e.keyCode === 46) {
        return false;
    }
});
</script>

hope it helps!

share|improve this answer
    
the metode is not working in sharepoint it is stil running the delete command –  Kenneth Foli Jørgensen Aug 27 '12 at 8:27
    
the bottom two examples 100% work as iv tested them myself using cewp, one doesnt allow delete key press but allows it on a textbox and the second one doesnt allow the delete key atall! –  ali Sharepoint Aug 27 '12 at 10:10
    
i have just testet the code and it is getting run but it is still delete the folder from a document library i is like it is running the delete before the script –  Kenneth Foli Jørgensen Aug 28 '12 at 8:26
    
ok sounds like a big issue and you are right! The only other suggestion is to make an eventReciver that checks on item deleting and if the user doesnt have the required privlages then stop the deletion else delete, here is a good example: social.technet.microsoft.com/Forums/en-US/… –  ali Sharepoint Aug 28 '12 at 9:12
add comment

Now, I find out the way to disable event delete on list view simply by edit code in core.js (..Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS).

Find the keyword "case Sys.UI.Key.del:" and comment HandleItemDelete like this.

function OnListViewKeyDown(ei, ctxNum) {
    var ctxCur = GetListContextFromContextNumber(String(ctxNum));

    if (ctxCur == null || ctxCur.inGridMode) {
        return;
    }
    var keyCode = ei.keyCode;
    var fShiftOrCtrlPressed = ei.shiftKey || ei.ctrlKey;

    if (IsCallOutOn()) {
        return;
    }
    switch (keyCode) {
    case Sys.UI.Key.del:
        /*HandleItemDelete(ei, ctxNum);*/
        break;

save and try.

share|improve this answer
    
You should really avoid modifying code in the hive(s). It is certainly not recommended by Microsoft, and your changes can be overwritten by any update made from Microsoft –  Robert Lindgren Jun 1 at 8:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.