How can I show line-breaks from string field in UI Page

Cris P
Tera Guru

Good morning everyone,

I have created a string field on the company table which looks like this, with this text in it:

find_real_file.png

I then have a client script which passes the value of that same field to a UI Page (using setPreference()):

	function invokeMessage(){
		//console.log('crisOut');
		var company = g_form.getReference('company', alertNote);

		function alertNote(company){
			var an = company.u_active_notification;
			if(!an){
				//console.log('crisNo ');
				return;
			}
			//console.log('crisYes ');
			var gdw = new GlideModal('active_notification');
			gdw.setTitle('Active Notification');
			gdw.setPreference('sysparm_activeNotification', an); //pass the active note to the ui page
			gdw.render();
		}
	}

 

I then grab the value in the UI Page like this:

	<j:set var="jvar_active_note" value="${sysparm_activeNotification}"/>
		
	<p class="modal-title h4 modal-header">${jvar_active_note}</p>

 

The end result is it displays the message fine, but note the line-breaks are not present in the UI Page:

find_real_file.png

What would be the best way to show the line-breaks, which are present on the string field on the form, in the UI Page too?

9 REPLIES 9

palanikumar
Mega Sage

Hi,

HTML will remove line breaks by default. If you want line break then you need to replace all line break with br tag.

Otherwise easy option is to include a pre tag. Pre tag will not omit line breaks

<j:set var="jvar_active_note" value="${sysparm_activeNotification}"/>
		
<p class="modal-title h4 modal-header"><pre>${jvar_active_note}</pre></p>
Thank you,
Palani

Hi there, thanks for your suggestion; I have tried the preserve tags but unfortunately they have no effect at all. The string remains without white space or line breaks.

 

Edit: Actually, just tried it again with the <pre> tags and this is the result:

find_real_file.png

Community Alums
Not applicable

Hi Cris,

transfer the value to the <style> tag as next,

      <tr>

      <td style="white-space:pre-line">

                  ${jvar_street}

          </td>

      </tr>

 

Please mark my answer as Correct & Helpful, if applicable.

Thanks

Sandeep

Hi Sandeep,

Thanks for your reply; I have tried setting the inline style to the same 'white-space:pre-line', but this has no effect and the string does not preserve the line breaks