This project has moved and is read-only. For the latest updates, please go here.

GetListItems and Multiline Text Fields Not Keeping Formatting

Oct 9, 2013 at 4:53 PM
Edited Oct 9, 2013 at 4:53 PM
Hello.....this is an awesome library. Excellent job.

I have run into an issue that I am not sure how to handle. I am using the GetListItems to get information out of my SharePoint lists. I have some columns set as multiline as plain text so users can enter text but not mess with things such as font changes and so on. SharePoint allows the users to do carriage returns and it keeps the formatting when you pull the list item up and look at the field. But when I try to bring it in using GetListItems and display it on a page, it all comes in as a single line (carriage returns missing). As an example, I access the items using:


Is there a different way to access the values that would allow me to retain the carriage returns? Or should I switch my fields to rich text instead of plain text?

Thank you,

Sam Tocco
Oct 9, 2013 at 5:01 PM
Hmm. I think you should get the carriage returns, or at least you should get anything the user has typed. Are you sure they aren't in what is returned from the call?

Oct 9, 2013 at 7:02 PM
As soon as I saw your reply the answer hit me. Line breaks are coming back in the return so I need to convert those to <br>. So I just used another function and replaced the line breaks with <br> tags and it worked.

Thank you for your help Marc.
Oct 9, 2013 at 7:09 PM
Great. Want to post the way you fixed the line breaks here in case others run into the same issue?

Oct 9, 2013 at 7:12 PM
Yes, I should have included the function I used.

Here is the URL to the site that has some documentation:

Here is the actual function I am using:
//Function to replace line breaks with <br> tags.
function nl2br (str, is_xhtml) {   
    var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';    
    return (str + '').replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
Oct 9, 2013 at 8:39 PM

May 4, 2015 at 7:56 PM
<pre> tag will work instead of div or wherever you are placing your data to keep line breaks.

must include this css for the pre tag.
      '<pre  style="font-size:16px; white-space:pre-line;">' + $(this).attr("ows_Permit_x0020_Type_x0020_Notes") + '</pre>'