NL to BR in a text forumla field

  • 0
  • 1
  • Question
  • Updated 4 years ago
  • Answered
Is it possible to create a forumla text field which replaces all the 'hidden' newline characters in a non HTML manual input text field to < br > characters in an HTML formula text field, so that it displays correctly?


Photo of David

David

  • 60 Points

Posted 4 years ago

  • 0
  • 1
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
No. An <input> control strips newline characters so they are not hidden but rather disappeared.

I am not clear what if you are (1) trying to patch up previously entered record or (2) refining a workflow so that new records are processed in the way you want. 
Photo of David

David

  • 60 Points
HI Dan,

It's to remedy existing / previously input data in the main.

So users have input into a multi-line text field.

This non HTML standard multi line text input field is subsequently used within an HTML formula field - and I was hoping I could preserve the new lines within it.

I'm confused by your comment re the newline characters not being hidden, but having effectively been stripped.

When the original input field is viewed in read only / view, it still has the original newlines?

BTW whilst ideally I want a solution I can retrofit to existing data, if the only solution only works with new input, then I'm happy to re-engineer around it, and apply only to new data.

David
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
>This non HTML standard multi line text input field is subsequently used within an HTML formula field - and I was hoping I could preserve the new lines within it.

I couldn't make any sense out of that so I tried to diagram your sentence but unfortunately my sentence diagramming tool only accepted 120 characters:

http://i.imgur.com/w4FXswC.jpg

>I'm confused by your comment re the newline characters not being hidden, but having effectively been stripped.

Text entered in to an <input> will be stripped of newlines. Text entered into a <textarea> will preserve newlines.
Photo of David

David

  • 60 Points
(-: So I'll try and keep my sentences as simple as possible.

I have a text field that users enter free format text into. Screenshot uploaded to my original question. This field has the 'Allow some HTML tags to be inserted in the field' unchecked

This first input field is used within another field (formula text) which has the 'Allow some HTML tags to be inserted in the field' checkbox ticked. This is because I need to use HTML formatting (mainly <br> and <b></b> tags) in the rest of the field content.

Does that make sense now?
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
>Does that make sense now?

That is definitely parsable:

http://i.imgur.com/TCB7vmT.jpg

Okay you appear to be using a text multiline field with some HTML allowed. Consider two cases: (1) some HTML allowed and  (2) no HTML allowed.

When no HTML is allowed the newlines that you enter into the <textarea> will be preserved but you can't enter bold <b> or any other tags.

When some HTML is allowed the newlines that you enter into the <textarea> will be stripped as whitespace and you will have to use typed in tags for new lines <br> and bold <b>.

QuickBase does not offer an option of using some HTML and preserving the newlines at the same time so you have to enter explicit <br>s in this case. Newlines are seen as whitespace within a <textarea>.
Photo of David

David

  • 60 Points
Thanks Dan - helps explain the problem but doesn't give me a solution.

)-:

Can the hidden newlines within the 'no HTML' field be identified within a quickbase formula?

If they can be found it would be possible to use a 'part' type formula to replace them with '< b r >'s.

David
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
The problem is that there could be any number of newlines in the field and QuickBase formulas have no way of iterating or looping over the field and making repeated substitutions. This is a fundamental restriction and is why you see so many so many native solutions work only for some arbitrary maximum of say 5. So you could write such a formula that only worked for n newlines but it would not be efficient or very maintainable and would only work if the number of newlines was less than some fixed value. Good luck with that approach.

Script never has this limitation. QuickBase should replace the formula language with JavaScript and a host of problems like this would simply evaporate overnight.
Photo of Ⲇanom the ultimate (Dan Diebolt)

Ⲇanom the ultimate (Dan Diebolt), Champion

  • 30,074 Points 20k badge 2x thumb
I am short time to come up with a working example but you could use this type of code with the image onload technique:

On Page LOAD:
$("#_fid_7").val($("#_fid_7").val().replace(/<br>/g,"\n"));

Just Before SAVE:
$("#_fid_7").val($("#_fid_7").val().replace(/\n/g,"<br>"));

If you use a multiline text field with some HTML allowed  (shown with fid=7 in code above) the above two jQuery statements will convert <br>s in the text field into newlines on page load and reverse the process converting newlines \n into <br>s just before saving the record. This way your user get the convenience of newlines with the "enter" key but have a <br> substituted just before the record is saved so the user is never distracted with seeing explicit <br>s in the <textarea>.

JavaScript solves all problems and the image onload technique is a hack to get your <script> to run on QuickBase authored pages automatically. BTW you can test these statements by typing them into your JavaScript console.

FWIW, you can play all sorts of games with <textarea>s such as:

(1) support textile, markdown, richtext etc

(2) create your own formula language

(3) create your own macro language (with sweetjs)

(4) create your own templating language based on ES6 template strings

Mas Que Nada