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.

3 comments:

  1. I've visited this article several times for reference. Many thanks. A new wrinkle, I have a MOSS list where i've enabled content type management and I want to hide the field that now appears at the top of the items when I go into an edit item view. there's something unique about that field that prevents this trick from working. any way to modify this approach to hide that field?

    ReplyDelete
  2. hey there, thanks for the comment! I believe there are a few ways.

    First, if you are switching everything to another content type / don't use multiple ones, you can change the order/default content type to the desired one then disable the multiple content types.

    Second, through javascript; see http://spff.codeplex.com/ for examples of how they did it. Either implement that project directly or include a CEWP and the needed jquery.

    Third, the least likely scenario is if you have manually built that content type through a WSP solution. If so, you could provide a parameter to the definition which disables the visibilty: http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/1594662d-4397-4847-9128-bb215177b410

    Let me know how it goes. Cheers and good luck!

    ReplyDelete
  3. Thanks for the tip! Could a similar solution be made to either bold the font of a particular column name in a form, or add a blank line between fields?

    ReplyDelete

firstly, thanks in advance for your comment - I don't get very many, so I'm sure to follow up if you leave me a way - secondly, come again.