28 September 2010

sharepoint trick to edit "new item form" by adding to url

Hide columns on NewForm, DispForm, EditForm in SharePoint list

To remove columns from appearing on a display, edit item, and new item form in SharePoint lists, e.g.:


The goal is to add some JavaScript into a Content Editor Web Part (CEWP) on the above page.

To add web parts to any page within Sharepoint:
On the URL of the form page you are, add to the end of it: &toolpaneview=2 (i.e. Or remove all the stuff (querystring) stuff at the end of URL and change it to DispForm.aspx?toolpaneview=2. The page will then change to Edit Mode:


From here, add a CEWP, content editor web part, to the page UNDER the form already on the page. This is very important, if will not work if the CEWP is not under the form. Modify the CEWP, open the source editor, and paste in:
<script type="text/javascript">
var containers =  document.getElementsByTagName("*");
for (var i=0;i<containers.length;i++)
 {
 if (containers[i].innerText == 'Recurrence' || containers[i].innerText == 'Workspace')
  {
  if(containers[i].tagName == 'H3')
   {
       containers[i].parentNode.parentNode.style.display = 'none';
   }
  if(containers[i].tagName == 'NOBR')
   {
   containers[i].parentNode.parentNode.parentNode.style.display = 'none';
   }
  }
 }
</script>
Save and close it. Now, the columns should be gone! Another quick tip, if you need to hide any other columns, in the code above find the section:
containers[i].innerText == 'Recurrence' || containers[i].innerText == 'Workspace'
For each column you need to hide, append it like this:
containers[i].innerText == 'Recurrence' || containers[i].innerText == 'Workspace' || containers[i].innerText == 'Title'
The code above will also hide the Title column. If you want to hide just one, remove the pipe characters ( || ) around each statement and remove all but the one you need:
containers[i].innerText == 'Location'





adapted from Kevin's post here.