function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
greggatssdgreggatssd 

Hard Returns in Text Areas

I did a BUNCH of searching on this. Actually found the exact question in a thread but somehow lost it and couldnt figure out the same search term...

Displaying text area data that includes hard returns via an html Scontrol loses the hard returns. The text displays fine on the SF detail record, but when loaded into html in an Scontrol (on the same detail page) the hard returns disappear and all the lines run together.

Isnt it as simple as replacing the character SF is using to store hard returns in text areas with the html friendly alternatives?

Im stuck and this is holding up one of our new apps... Thanks for any insight.



Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

The line breaks are there, per se, but the browser ignores them as white space; this is an HTML standard. You can circumvent this by using the <pre> tags. For example:

<pre>
{!Account.Custom_Field__c}
</pre>

In the S-Control, this will appear as:

» Item 1
» Item 2
» Item 3

I hope this helps.

~ sfdcfox ~

All Answers

SteveBowerSteveBower
Is this the post you're thinking of:

http://community.salesforce.com/sforce/board/message?board.id=general_development&message.id=4678
 
-S
greggatssdgreggatssd
Nope, didnt find that one. The thread I found was basically this...


I enter the text below into a Salesforce text area:

Sample bullet list:

• Bullet one
• Bullet one
• Bullet one
• Bullet one
• Bullet one


The Salesforce Detail page displays all the line breaks, when calling that field into an htlm Scontrol this is what I get:

Sample bullet list: • Bullet one • Bullet one • Bullet one • Bullet one • Bullet one


All line breaks seem to be spaces. What am I missing/how do I display text areas in Scontrols with line breaks?




SteveBowerSteveBower
Sorry, How about this:

http://community.salesforce.com/sforce/board/message?board.id=general_development&message.id=4173

-S

ghealyghealy
That thread looks to be using a hidden field reference and JS to remove the returns from text area data to eliminate an error. I just want to display carriage returns that are in the field.

I wonder what the code is that Salesforce uses to display the contents off text areas on the Detail pages? Thats what I need...it works fine.

Thanks for the help.


greggatssdgreggatssd
Nobody knows a way to do this...?


SteveBowerSteveBower
This code works.  I don't know if this is what you're trying to do, but if not, then I think I, and perhaps others, just aren't understanding your problem clearly.  Best of luck, Steve.

Code:
<html>
<head>
    <script type="text/javascript" src="/js/functions.js"></script>
    <script src="/soap/ajax/9.0/connection.js"></script>
    <script language="JavaScript">
function saveit() {
 var e = document.getElementById('ta');
 var ids = new Array("{!Account.Id}");
 try {
  // query for the record with the local id.
  var recs = sforce.connection.retrieve("Id, Description","Account",ids);
  // Update it.
  recs[0].Description = e.value;
  // Now update the SFDC record.
  var up = sforce.connection.update(recs);
 } catch(x) {
  alert("Exception: " + x);
 }
 // Now we're done.
 window.close();
}
</script>
</head>
<body>
<form id="testform" action="">
 <textarea id="ta" rows="20" columns="80">{!Account.Description}</textarea>
 <button type="submit" onclick="saveit();">Update Description</button>
</form>
</body>
</html>

 


SteveBowerSteveBower
Sorry, if it's not obvious, you need to make that an s-control and launch it from a custom link or button from an Account object.  (Perhaps inline it, I didn't try that.)  Best, Steve.

greggatssdgreggatssd
I dont speak Javacsript as of yet. What does that  script do? Do I need to feed it any field names or anything?

Here is a picture (I should have done this from the start...):

My problem is that the html that formats the coupon using an html Scontrol (at the bottom), removes the hard returns in the text areas. Note the Inscludes field in the Salesforce generated detail record.

Im sure Im doing something stupid but its driving me nuts...



A separate note: Can I use an html format like that coupon via an Scontrol to display a list of them?


ghealyghealy
Ran this by tech support and they told me they cant even respond "becuase its a custom application and html".

Am I the only one with this issue? All Im trying to do is display a text area field with the line returns in html...


SteveBowerSteveBower

You're not the only one with the issue, but you already have the solution. 

Take a look at the code I posted where the <textarea> section is defined.  That's where the value of the field (description in this case) is substituted into the HTML and it maintains the carriage returns, etc.

All the rest of the code does is process the Submit click to actually update the record with the new value of the Description after you edit it.  Since you just have a read-only usage, you don't need any of that.

Either way, best of luck.  Steve.

ghealyghealy
I dont want an html text area to display, just the data as its displayed on the detail record from SF.

Thanks for your help with this.


sfdcfoxsfdcfox

The line breaks are there, per se, but the browser ignores them as white space; this is an HTML standard. You can circumvent this by using the <pre> tags. For example:

<pre>
{!Account.Custom_Field__c}
</pre>

In the S-Control, this will appear as:

» Item 1
» Item 2
» Item 3

I hope this helps.

~ sfdcfox ~

This was selected as the best answer
ghealyghealy
Thats what I was looking for! Figures it was standard html, thats what I get for using these wysiwyg html editors...

Thank you!!!!