views:

37

answers:

1

I have a summary single-line text column in SharePoint 2007 that is a truncation of a multi-line text column. Going through the complicated process to get there, it turns into text which then needs to be converted back to HTML, so that the tags like <div> don't show. The following code works if the multi-line column is rich text, but not if it's enhanced rich text. Does anyone have the code handy to make this work? (Note: I am working on it but haven't really done any javascript up until now, so it's slow going).

<script type="text/javascript">
  var theTDs = document.getElementsByTagName("TD");
  var i=0;
  var TDContent = " ";
  while (i < theTDs.length)
  {
    try
    {
      TDContent = theTDs[i].innerText || theTDs[i].textContent;
      if (TDContent.indexOf("<div") == 0)
        {
          theTDs[i].innerHTML = TDContent;
        }
    }
  catch(err){}
  i=i+1;
  }
</script>

The result I'm getting now is nothing visible, because with enhanced rich text the div tag is longer than my 45 character truncation limit.

+2  A: 

How about using Christophe's techniques to output HTML using a calculated column.

Specifically he has written javascript that will turn the encoded HTML (which you've now got) into HTML.

Add the following into a Content Editor Web Part (CEWP) on the same page.

<script type="text/javascript">
/*
Text to HTML Lite - version 2.1.1
Questions and comments: [email protected]
*/

function TextToHTML(NodeSet, HTMLregexp) {
   var CellContent = "";
   var i=0;
   while (i < NodeSet.length)
   {
      try 
      {
         CellContent = NodeSet[i].innerText || NodeSet[i].textContent;
         if (HTMLregexp.test(CellContent)) 
            { NodeSet[i].innerHTML = CellContent; }
      } 
      catch(err)
      {}

      i=i+1;
   }
}

// Calendar views
var regexpA = new RegExp("\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*");
TextToHTML(document.getElementsByTagName("a"),regexpA);

// List views
var regexpTD = new RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");
TextToHTML(document.getElementsByTagName("TD"),regexpTD);

</script>
Ryan
I had actually tried that code, and it didn't do the job, but I'll try again.
Lance Roberts
Tried again, I think the problem is that the truncation is happening before the html conversion, so it only has part of the large div tag to work with. I need to figure out how to apply the html conversion before the truncation. For now, I've just changed the final calc column to a large enough width so that the div tag is caught, now the field only breaks when there's an attachement.
Lance Roberts
I tried is again after I changed the width, but it won't work, I'm thinking this code only works if it has the entire html piece, while the code I'm using will work with only the front end (as long as it has the whole front tag).
Lance Roberts