Sunday, May 3, 2009

Sharepoint Customization using java script

We have a list, but we want to hide some of the fields from being displayed in the edit or new item screens. By default when you create a list and add columns, you can hide columns via custom views, but when you create or edit an item you get the lot, whether you like it or not.
Here is the WorkAround :
function getTagFromIdentifierAndTitle(tagName, identifier, title)
{
var len = identifier.length;
var tags = document.getElementsByTagName(tagName);
for (var i=0; i < tags.length; i++)
{
var tempString = tags[i].id;
if (tags[i].title == title && (identifier == "" tempString.indexOf(identifier) == tempString.length - len))
{
return tags[i];
}
}
return null;
}

(script language="javascript" type="text/javascript")
_spBodyOnLoadFunctionNames.push("hideFields");
function hideFields()
{
var control = getTagFromIdentifierAndTitle("Input","TextField","Serial Number");
control.parentNode.parentNode.parentNode.style.display="none";
}
(/script)