Tuesday 13 August 2013

Sharepoint - dispform.aspx, hide button in ribbon bar


1. The ribbon bar in dispform contains some buttons. They might not need in some places due to permissions. They can be hided using javascript.



2. Use IE. Right click on the dispform and choose view source.





3. In the source we can find the end user id of the particular button
    ex.1) Ribbon.ListForm.Display.Manage.EditItem-Large is for "Edit Item"
         2) Ribbon.ListForm.Display.Manage.VersionHistory-Medium is for "Version History" etc.

    -- Choose the appropriate id of the button that you wish to hide.




4. Use this script
       <script type="text/javascript">
    function hideEdit() {
        var edit = document.getElementById("Ribbon.ListForm.Display.Manage.EditItem-Large");
        edit.style.display = "none";
    }       
    _spBodyOnLoadFunctionNames.push("hideEdit");
</script>

         -- Use individual functions for buttons that you wish to hide.
         -- don't forget to call it using _spBodyOnLoadFunctionNames.

5. On the dispform move to page edit.


6. Click Add Web part and insert content editor web part.
     

7. Click on "click here to add new content".

8. On format text ribbon choose edit html source.





9. Paste the script inside the dialog box and click ok.





10. Now edit the web part and make it hidden.