Thursday, March 28, 2013

Using word-wrap for an AspMenu SharePoint web control with long menu items

I have an AspMenu SharePoint web control with long menu items that do not respect the width of the table cell that I've set even though I have the property 'ItemWrap' set to 'True'. The biggest culprit is users wanting to use a series of  underscores to separate one group od links from another. To keep an extra long series of underscores from pushing the table cell wider, I'm using the stylesheet rule 'word-wrap' as shown below.

The ASPMenu control creates this hierarchy of tables. 

div#s4-leftpanel table tr td table
{
       table-layout:fixed;
}
div#s4-leftpanel table tr td table tr td
{
       word-wrap:break-word;
}

Monday, March 11, 2013

Hiding SharePoint list columns from NewForm.aspx using JavaScript

There are times I create a column in a SharePoint custom list and I don't want anyone with Contribute rights to alter the default value. In the NewForm.aspx and EditForm.aspx pages I add the following script to a CEWP on the page.

<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");
HideField("Remote Item ID");
</script>