Many times we require to hide specific field in new form, disp form and edit form. This time we will do it with the help of javascript. We can do the same thing with the help of SharePoint API. However we will cover here that how to achieve the same with the help of JavaScript.
Let us go to calendar and click on new. You will now be on Newform.aspx. We can see here one field named “WorkSpace”. If we don’t want user to create any workspace here, then we can hide this field with the help of JavaScript code.
To hide a specific field, insert one content editor web part on the page and then just copy and paste the following code. Insert this web part below the new form web part.
<script type="text/javascript">
function HideField(title){
var header_h3=document.getElementsByTagName("h3") ;
for(var i = 0; i <header_h3.length; i++)
{
var el = header_h3[i];
var foundField ;
if(el.className=="ms-standardheader")
{
for(var j=0; j<el.childNodes.length; j++)
{
if(el.childNodes[j].innerHTML == title || el.childNodes[j].nodeValue == title)
{
var elRow = el.parentNode.parentNode ;
elRow.style.display = "none"; //and hide the row
foundField = true ;
break;
}
}
}
if(foundField)
break ;
}
}
HideField("Workspace");
</script>
After you’ve inserted this code, just look at the result shown below.
That’s it. Your job is done. You can apply the same code in disp and edit form as well.
12 comments:
Where should we add this Code?
you can write this code on
newform.aspx/Editform.aspx/dispform.aspx means on List forms.
Refer this link http://www.sharepointkings.com/2008/05/how-to-edit-list-forms-like-newformaspx.html to know how to edit list pages.
Can this code be placed in a webpart with an audience enabled? Want items to be hidden for certain SharePoint groups.
Yes Brad, you can use this in webpart.
Hi,
Thanks for the article..
However,after applying the fix,The field is still visible in edit form page.
Any suggestions on why this is happening?
Thanks
Priyanka,
just check whether javascript is working (by putting alert).
if its working then check the name of the control in view source and use that name to hide.
How could you format this to hide a field based upon a value in a dropdown?
marc,
refer this link
http://www.sharepointkings.com/2010/05/required-field-using-jquery-in-newform.html
this may help you
Nice post. I realize it's a year later... Is it possible to adapt this to SharePoint 2010 (Modal dialogs)?
@Clem, yes its possible
its a normal SharePoint page only which SP2010 is opening in model dialog.
if you found URL and try to open it in normal window then also it opens. so you can easily apply JavaScript on the same.
almost three years later and this snippet works like a charm. I added it to some forms today.
Thanks!
Post a Comment