Tuesday, February 16, 2010

Hide Delete Item Option in Form Toolbar of Custom List Form using SPD

To Hide the Delete Item option from the Form Toolbar using Javascript in SPD, use the following javascript function

function HideDeleteItem()
{
var aList=document.getElementsByTagName("a");
for(i=0;i {
if(aList[i].innerHTML=="Delete Item")
{
aList[i].parentElement.parentElement.style.display="none";
}
}
}

This can also be achieved using jQuery.

$(document).ready(function() {
$(”td.ms-titlearea”).hide();
$(”a[title='Delete Item']“).parent().parent().parent().hide();
$(”td.ms-separator:nth-child(4)”).hide();
});

The advantage of using this jQuery is that it also hides the separator whereas the other normal function doesn't help to achieve this.

2 comments:

  1. it hides the button , but it appears for a brief period of time when the page loads... can we stop that?

    ReplyDelete
  2. I think the easiest way to do -
    Open SPD > EditForm.aspx > in code find standard toolbar webpart code > Make the Control Mode to "New" which will get rid of "Delete Item"

    ReplyDelete