Multi-Line Fields

Having lots of fun programming my new TW app and feeling much more confident on the brackets front - a very positive day!

However, have come across one niggling issue - multi-line fields.
I would like my data tiddlers to store multi-line fields and not just in the text area as this is used to display the data in a formatted way. However, if I add a new data tiddler with the multiline field containing

line 1
line 2
line 3

then once stored, we loose the line breaks and the 'formated; display just shows

line 1line 2line 3

I have been searching for a solution and have come across the discussion from 2022 related to multi-line editing but it is old. Is it still valid for the current TW version?

Can someone suggest a solution to my issue?

My code at present is

Exhibition Essay: <$edit-text tiddler="$:/TLS/Exhibition/Essay" tag="textarea" default="" placeholder="the text of any essay/artist statement"/>

-----
<$button>

     <$action-createtiddler 
          $basetitle={{{ [{$:/TLS/Prefix/Exhibition!!exhibition_id}addprefix{$:/TLS/Prefix/Exhibition!!exhibition_prefix}] }}}
          exhibition_essay={{$:/TLS/Exhibition/Essay}}
           $template="$:/TLS/CreateTemplate/Exhibitions"
     />

Add this item

</button>

bobj

Bob, Multi line fields already work, it is just the single line editor in the edit template that if tickled saves it without the line feeds.

  • The Trick is to hide such fields from that editor, by making it a system field.
  • Then if needed adding back a custom field editor for text areas not single line on those fields.

Because this is not by default a “standard tiddler” you should check it survives a save and reload, but it has worked for me.

The line breaks you enter are actually preserved in the resulting tiddler. However, when you edit that tiddler the exhibition_essay field is displayed using a tag="input" rather than a tag="textarea" so it LOOKS like the line breaks are gone, but they are, in fact, still there… as long as you don’t change the value in that field.

The real problem is displaying the field value with the line breaks intact. By default, HTML rendering does not preserve line breaks and reduces all other whitespace separators to single space characters when displayed.

However, this rendering handling can be controlled by using CSS, like this:

<div style="white-space:pre;">{{!!exhibition_essay}}</div>

see white-space - CSS: Cascading Style Sheets | MDN for more info

enjoy,
-e

You may have a closer look at my field-editor plugin, which is introduced at:

A video how it is used in combination with the Field Visibility Plugin can be found at YouTube:

Field Editor & Field Visibility Plugin