Click here to Skip to main content
Licence CPOL
First Posted 24 Jan 2009
Views 30,988
Downloads 95
Bookmarked 28 times

SharePoint Customization Tricks – Part 2

By Ayman M. El-Hattab | 24 Jan 2009
Two more tricks for SharePointers :)

1

2

3
2 votes, 66.7%
4
1 vote, 33.3%
5
4.10/5 - 3 votes
μ 4.10, σa 1.01 [?]

Introduction

This multipart series of articles is intended to help you get ramped up with SharePoint customization. It's about modifying the default SharePoint user experience, list forms customization, branding, skinning SharePoint portals, etc. In Part 1, we introduced a generic function that can be used to hide the list view toolbar menu items (e.g., New Item, Upload, Edit in Grid view, etc.). If you haven't read it yet, I would encourage you to do that first. Here, I'll show you two other tricks for customizing the list form toolbar.

Trick #2: Hiding List Form Toolbar Menu Items!

dispform.JPG

Sometimes, you need to remove some items from the toolbar that appears at the top of DispForm.aspx. Unfortunately, the "HideCustomAction" feature can merely hide the items which have been rendered through the "Custom Action" feature framework such as Site Actions and Site Setting, so let's take the same approach we took in Part 1, which is delving back into the world of JavaScript, which I really find very handy when it comes to SharePoint customization.

The following function can be used to hide any toolbar item in dispform.aspx. Just call the function passing the names of the items comma separated (e.g., New Items, Alert Me, etc.). The function removes the items, and of course, the images rendered beside them (if found). Trick #3 will deal with where and how you can add the function to your list form.

hideFormMenuItems("New Item","Alert Me");
 
function hideFormMenuItems()
{  
    var titleToHide="";
    var anchorTag;
    var allAnchorTags = document.getElementsByTagName('a');
    for(var i = 0; i < hideFormMenuItems.arguments.length; i++ )
    { 
        titleToHide = hideFormMenuItems.arguments[i];
        if(titleToHide!='Alert Me')
        {
            for (var j = 0; j < allAnchorTags.length; j++)
            {
                anchorTag= allAnchorTags[j];    

                if (anchorTag.title.indexOf(titleToHide)!=-1)
                {
                    anchorTag.parentNode.parentNode.parentNode.parentNode.
                    parentNode.style.display="none";
                    anchorTag.parentNode.parentNode.parentNode.parentNode.
                    parentNode.nextSibling.style.display="none";
                    break;
                }
            }
        }
        else
        {
            for (var k=0; k < allAnchorTags.length;k++)
            {
                anchorTag= allAnchorTags[k];
                if (anchorTag.id.indexOf("SubscribeButton")!=-1)
                {  
                    anchorTag.parentNode.parentNode.parentNode.parentNode.
                    parentNode.style.display="none";
                    break;
                }
            } 
        }
    }

    var allSpanTags = document.getElementsByTagName("span");
    var spanTag;
    var toolbarRow;
    var lastCell;

    for(var m=0; m < allSpanTags.length;m++)
    {
        spanTag = allSpanTags[m];
    
    if(spanTag.id=='part1')
    {
        toolbarRow = spanTag.childNodes[2].firstChild.firstChild;
        lastCell = toolbarRow.lastChild.previousSibling;
        while(lastCell.style.display=='none')
        {
            lastCell = lastCell.previousSibling;
        }
        if(lastCell.innerText == '|')
        {
            lastCell.style.display='none';
            break;
        }
    }
}

Kindly note that the function is case sensitive, so take care of the case the toolbar item names are rendered with.

Trick #3: Adding JavaScript Through CEWP!

The content editor Web Part gives you the ability to add any valid HTML on the Web Part page you place it in, and this surely includes <script> elements. The major advantage when using the content editor Web Part is that anyone with Designer permissions can do it quickly and easily.

Nice and easy, let's do it, just go to Site Actions, Edit Page!!

p2t2_editpage.JPG

Where the heck is the Edit Page menu item?!! Just like the old version, it's not available, I’m still not sure why they did that!

Trick #3: Just append "&ToolPaneView=2" to the URL, and you will have DispForm.aspx in Edit Mode in your browser.

addContentEditor18.JPG

Add a content editor Web Part just below the Web Part that renders the list form, and insert the JavaScript of Trick #2 as shown in the figure below. (It's preferable to mark the content editor Web Part as hidden.)

addContentEditor12.JPG

addContentEditor13.JPG

Exit the edit mode…

dispformafter.JPG

Tremendous, we managed to hide "New Item" and "Alert Me". What about renaming "Edit Item" to "Edit Program" and removing "Delete Item" but leaving the small image (x)? That is what I'm going to cover in Trick #4 in the next part!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ayman M. El-Hattab

Architect

Egypt Egypt

Member
Ayman El-Hattab is a SharePoint MVP, Developer, Author & Speaker. He is a Microsoft Certified Solution Developer as well as a Microsoft Certified Technology Specialist in SharePoint. Ayman writes articles about topics in relation to SharePoint and its related technologies for online magazines, publicly speaks for numerous user groups, offline communities and SharePoint Saturdays, is the founder of www.SharePoint4Arabs.com, organizes events for Egypt SharePoint User Group and you will always find him active at MSDN and Technet forums. Ayman has also been recognized by Microsoft as Most Valuable Professional (MVP) in April 2010.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralDoes not work with Google Chrome PinmemberJeffWG9:33 17 Jun '11  
Generalhide other items Pinmembercb1624x6:49 6 Oct '10  
QuestionCan this be used to hide Upload and Actions menu? Pinmembercolecg3:40 13 Sep '10  
Generaldon't know why, but... Pinmembercbennett51998:55 8 Mar '10  
QuestionHi it is working fine ..But when we will get Trick #4 from your side? PinmemberSuresh Kumar.A1:13 9 Sep '09  
AnswerRe: Hi it is working fine ..But when we will get Trick #4 from your side? PinmemberAyman M. El-Hattab1:58 9 Sep '09  
GeneralCant get it working Pinmemberjerseyden8:10 13 May '09  
GeneralRe: Cant get it working PinmemberAyman M. El-Hattab14:28 13 May '09  
GeneralRe: Cant get it working Pinmemberjerseyden21:21 13 May '09  
GeneralRe: Cant get it working PinmemberAyman M. El-Hattab22:47 13 May '09  
GeneralRe: Cant get it working Pinmemberjerseyden7:06 14 May '09  
GeneralRe: Cant get it working PinmemberAyman M. El-Hattab11:48 14 May '09  
QuestionRe: Cant get it working Pinmemberhpcdr21:00 24 Mar '10  
GeneralRe: Cant get it working Pingroupvimalkumarsinghal1:03 14 Sep '10  
GeneralIt works. PinmemberMember 14325681:07 8 Apr '09  
GeneralRe: It works. PinmemberAyman M. El-Hattab14:46 9 Apr '09  
GeneralProblem Pinmemberaudunms2:19 20 Mar '09  
GeneralHi ... the code is not working.... Pinmemberjacobsaumy23:18 14 Feb '09  
GeneralRe: Hi ... the code is not working.... PinmemberAyman M. El-Hattab1:13 25 Feb '09  
GeneralRe: Hi ... the code is not working.... Pinmemberaly_ashour22:33 25 Feb '09  
GeneralRe: Hi ... the code is not working.... PinmemberAyman M. El-Hattab22:41 25 Feb '09  
GeneralRe: Hi ... the code is not working.... Pinmemberaly_ashour23:10 25 Feb '09  
GeneralRe: Hi ... the code is not working.... Pinmemberaly_ashour1:39 26 Feb '09  
GeneralRe: Hi ... the code is not working.... PinmemberAyman M. El-Hattab0:06 28 Feb '09  
GeneralRe: Hi ... the code is not working.... Pinmemberahmadzia67316:27 21 Jul '10  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120209.1 | Last Updated 24 Jan 2009
Article Copyright 2009 by Ayman M. El-Hattab
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid