3

i have one long text area field and i used it on my visualforce. my long text area field value is

- Fees are valid only for the payment of the Grade specified in this Letter of Offer.\n- Fees include: 2 sets of school uniforms, fieldtrip around the xxx area, E-Book material, and in-house co-curricular activities.\n- Request for changes to instalment plans must be made 10 days prior to the due date of the payment.\n- Terms and Conditions from the Admissions Policy will apply.

, the idea is i change all '\n' to <br/> so it can put line break in one field. here's my visualforce look like

<apex:outputText value="{!SUBSTITUTE(JSENCODE(loo.Note_SA__c),'\n','<br/>')}" style="white-space:pre;" escape="false"/>

the outcome is not like my expected

  • Fees are valid only for the payment of the Grade specified in this Letter of Offer.\
  • Fees include: 2 sets of school uniforms, fieldtrip around the JABODETABEK area, E-Book material, and in-house co-curricular activities.\
  • Request for changes to instalment plans must be made 10 days prior to the due date of the payment.\
  • Terms and Conditions from the Admissions Policy will apply.

in every end of the list there is '\' symbol. i don't know where it comes. Do you have any idea about this ?

3 Answers 3

6

<apex:outputText value="{!SUBSTITUTE(JSENCODE(loo.Note_SA__c),'\n','<br/>')}" style="white-space:pre;" escape="false"/>

change this into this

<apex:outputText value="{!SUBSTITUTE(JSENCODE(loo.Note_SA__c),'\\\n','<br/>')}" style="white-space:pre;" escape="false"/>

It will works for you. Thanks for the update @VigneshwaranG

2
  • it didn't work bro. i already use it but no use. have any idea? Oct 2, 2015 at 16:01
  • 2
    Use \\\n since you need to escape the escape character added for escaping \ Oct 2, 2015 at 16:43
4

a more simple and best solution would be to add the css pre-wrap which conserves New lines, Spaces and tabs, Text wrapping

  <apex:outputtext style="white-space:pre-wrap;" value="{!donationText}" escape="false" /><br /> 

Please note donationText is a long text area

1

Like @VigneshwaranG said. just create escape character for escaping .

so i replace \n to \\\n

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .