6

I am having trouble with apex:outputField and a long textarea field. Salesforce appears to be inserting extra spaces on lines after BR tags after the page is rerendered following an actionFunction.

Here is the text exactly as it appears within the long textarea field:

The following questions and requirements are needed to continue your on-boarding. Once you have finished, you will have access to our system for client and resource management.

1. Fill in some demographic information
2. Sign the advocate handbook

If you have any questions, please contact your Program Manager.

Welcome to the team!

Everything is flush against the left margin.

The text appears correctly when the Visualforce page is first invoked. However, after an actionFunction rerender, the spaces are inserted.

Here is the resulting HTML after apex:outputField:

<span id="blah blah blah">
The following questions and requirements are needed to continue your on-boarding. Once you have finished, you will have access to our system for client and resource management.
<br>
<br>
 1. Fill in some demographic information
<br>
 2. Sign the advocate handbook
<br>
<br>
 If you have any questions, please contact your Program Manager.
<br>
<br>
 Welcome to the team!
</span>

Note that all the text lines after BR tags are indented by a space. This causes problems because we are also using Markdown to do some extra formatting for this div.

Anyone know how I can eliminate those extra spaces? I've already tried outputText but that does not suit our needs.

Thanks

David

5
  • When you say you're using markdown, do you mean you are using something like showdown.js to convert markdown text to html? If so how about if you used apex:outputText instead of apex:outputField since you wouldn't need the <br>'s in that case?
    – Tim Smith
    May 6 '14 at 18:02
  • Tim - yes we want to use Markdown js and enter the markdown characters in the long textarea field. I've tried with outputText but I couldn't get the Markdown line break function to work, plus the markdown line break style seems cumbersome to use (two spaces and the word "return"). May 7 '14 at 18:21
  • @TimSmith it looks like when an outputText is included in the original page rendering, it respects line breaks within the underlying field - but when it's included as part of a rerender loop, the newlines are simply not there.
    – Benj
    May 8 '14 at 14:56
  • It definitely looks like the spaces are being inserted by Salesforce. I just reviewed this page again, inspecting the actual requests in the Network panel of debug tools. You can see the extra spaces in this gist.
    – Benj
    May 22 '14 at 14:29
  • @DavidCheng it might be helpful to update the question to clarify that the extra spaces do not appear when the visualforce page is initially rendered, but just when it is rerendered following an actionFunction.
    – Benj
    May 22 '14 at 14:30
1

Is it possible that something else on the page is altering the DOM?

I tried the following.

  1. Added a custom Long Text Area field to Account with the API name TestLongTextArea__c
  2. Created a Visualforce Page with the content.

    <apex:page standardController="Account"> <apex:outputField value="{!account.TestLongTextArea__c}" /> </apex:page>

  3. Loaded your test data into the custom field for a random Account.

  4. Previewed the Visualforce page and added the Id query string parameter with the value from step 3.
  5. Used view page source in chrome.

Page source

The same content in Notepad++ so I can see the EOL chars:

enter image description here

Looks right to me. What OS and browser are you using? It might be something odd with the carriage returns and line feeds.

3
  • Hi Daniel, thanks for taking the time to test. I'm using Inspect Element in Chrome on Mac. The text is shown as " 1. Fill in some information" etc. When I try Developer -> View Source, I actually cannot find any of the text. There is a lot of javascript on this page, including JQuery and Backbone, and I'm not a Javascript expert, so I'll have to check with my colleague to see why the text is not appearing in the source view. May 7 '14 at 18:30
  • Probably not showing up in source view because that shows the original source when the page is first loaded, and this is filled in after a actionFunction/reRender. In contrast, the Inspect Elements panel shows the current state of the page.
    – Benj
    May 8 '14 at 14:55
  • @DanielBallinger can you try this test again, but don't show the outputField by default - instead, rerender its section following an actionFunction? We're seeing a difference in how these render in initial load vs. rerender, and I'm curious if you are, too.
    – Benj
    May 8 '14 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.