How can I get newline(enter) in a text field?

I have a requirement, where I would like to use sentences/paragraphs in newlines inside a text field. I have a data collection column called “Description” of type text. In this field I have written two long paragraphs.
While opening the web page, the description paragraphs are coming in one line. I need them to come with a newline between them.

Issue is :


Solution I need :

2 Likes

Hey,
You can simply connect it to a rich text field and design the text however you want.

Good luck,
Tal.

Hello Tal,

Thank you for your reply and solution. However there is a problem while doing so.
The problem is, the rich-text format texts/paragraphs are not saved in database, no matter how many times you click save.
I have read few other posts on same issue. There is no concrete solution to this. Any solutions do you suggest?

Cheers!

Hi,
How exactly are you trying to save the rich text in the database?
Please share your code and a screenshot of the database or a link to the editor.

Dear Or,

I edit the sandbox database, in the editor itself, then sync to live database then save button on the top.

I haven’t used any code for the text field. Just connected the corresponding dataset.

Now you can see the result as below. Both font and font color are different.

Also, you can go to the test website and click on “FAQS”: https://retailshopprs.wixsite.com/new-copy/products/Asus-Casual-Laptop-Backpack

Thank you very much!!

Hey,
I played with it and was able to change the color to black. I saved it for you:

When you change color, you should click on the “Done” button to apply the change. I guess that you changed the text color but haven’t clicked the “Done” button. Therefore, the change wasn’t saved:

Best,
Tal.

I understand the rich text solution, but what if I am generating one hundred dynamic pages and would like the front to be whatever I select on the template page. In the rich text solution, I would have to edit all 100 of the cells in the database to have the desired font and color? Just to get carriage returns and line feeds?

Am I missing something?

Hi Deborah,
You can also use the new line escape character \n to create a new line and set the new string to the text element:

const firstWord = "Hello";
const secondWord = "World";
$w('#text1').text = `${firstWord}\n ${secondWord}`;

Good luck,
Tal.

How would this code relate to entries in my database. Please show a database entry of text with this inserted.

Alternatively, is there a way to set default font and color for a rich text column in a database.

Hey Deborah,
There’s no option to set a text theme for a rich text. You can ask it as a feature request here .
As for code entries in the database please be more specific of how you would like the text would look like. On which cases you want to have a new line? It depends what you would like to achieve.
You can use the new line character ( as explained above) and use the insert function to insert a new record to your collection. If you want me to help you with code, I need more details of how you would like the string to look like and on which occasions you insert a new record to your collection.

Best,
Tal.

I am not sure I have been making myself clear.

I would like to be able to add a text database entry that looks like this:

The quick brown fox jumped over the lazy brown dog.

I am the beginning of a new paragraph.


And have it appear on my page as

The quick brown fox jumped over the lazy brown dog.

I am the beginning of a new paragraph.


Right now it appears when dynamically generated:

The quick brown fox jumped over the lazy brown dog. I am the beginning of a new paragraph.

As my carriage return/line feed has been eliminated.

====

All I am looking for is the ability to get the newline/carriage return in a normal text box. I wouldn’t think I would have use the APIs just to get a standard escape sequence like carriage return/line feed in a text box.

Is there no escape sequence you can put in a regular text entry in the database to preserve this? I am not looking for anything fancy here.

Hi Tai,

I have a similar question of adding a new line to the text that is saved in the collection.

I want to create a form for my users to input paragraphs, which will be displayed in a dynamic page. I have connected the form text box to my dataset, which connects to my collection’s field with field type setting as “text”.

I have tried the form in preview mode, but the information saved in my collection has no line separation. Can you teach me how save paragraph entered by users into my collections which can be used to display elsewhere?


Example of my problem (borrowing the text from retailshopprs above).

User input in form:


Information saved in collection:


Information displayed in collection:

How to save and display the paragraphing inputted by the user?

Has anyone solved the problem of inputting a newline carriage return into a normal text box in the database? That is, is there a typing sequence to input the newline character into my text in a database entry? This seems so fundamental, I’m sure I am missing it. I would like to format paragraphs in normal text in the database and do not want to use rich text because I am generating hundreds of dynamic pages. I do not want to have to set the formatting for each cell in my rich text field just to get a carriage return. Gurus, am I missing something?

I have a work around solution to this annoying problem, which seems very reliable, and will work for you if you can change your text fields to HTML (with tags for p1, p2, h2 etc for desired styles and
for return carriages). In the most simplest of cases you would just need to decide which Wix style you want for the chunk of text eg) p1, p2 or whatever, and put
where you would like the new lines to occur.

So the HTML would be

blah blah blah
blah blah blah
blah blah blah

After implementing the solution as explained below, this would show as

blah blah blah
blah blah blah
blah blah blah

In the style of p1.

So then, rather than using Text, you can instead store this formatted HTML inside a text field in your collection (the field type for this MUST be text not rich text).
Then, in order to get this displayed correctly on the dynamic page as per above, you simply insert this HTML into the relevant element on the page (which doesn’t even need to be connected to any data), using wix code and the following method. You will have to adapt to your field names and dataset obviously.

Here is my code (NB: jobSummary, companyDescription, reviews, personSpecification are the field keys where the HTML is stored.)

$w(" #dynamicDataset “).onReady( () => {
let jshtml= $w(” #dynamicDataset “).getCurrentItem().jobSummary;
let cdhtml= $w(” #dynamicDataset “).getCurrentItem().companyDescription;
let rvhtml= $w(” #dynamicDataset “).getCurrentItem().reviews;
let pshtml= $w(” #dynamicDataset ").getCurrentItem().personSpecification;
$w(’ #text10 ‘).html = jshtml;
$w(’ #text18 ‘).html = cdhtml;
$w(’ #text31 ‘).html = rvhtml;
$w(’ #text19 ').html = pshtml;
} );
});

The .html reference is here:- https://www.wix.com/code/reference/$w.Text.html#html

Providing you have all the p1, p2 etc tags in place then your text will appear exactly as the default p1, p2 etc styles which are set up in your wix site, and the
tags will create new lines where desired.

I am currently importing data into my Wix database collection. One of my columns has a lot of text separated by commas. I would ideally like a new line on my dynamic page for each instance of a comma. Is there anyway to do this?

I have a few ollections , each with a “product “ column. Is there anyway for a user of a dynamic page to filter to a product name, and have that filter reply to each of the tables that has that product?

I assume that you’ve still not received a solution to this?

I haven’t got html as an option. How did you set that? And what format is ‘tags’? It just deletes the content of your field as far as I can tell…?

Old post from 2018 being closed.

If you are using the HTML format then you will need to create the HTML yourself as shown in the linked page.
https://support.wix.com/en/article/corvid-about-formatting-text-elements

Otherwise you can simply use a rich text field in your dataset and set it all up through the dataset field itself and don’t alter any settings in the editor for fonts etc when you use it or it will override the dataset field settings.
https://support.wix.com/en/article/connecting-text-elements

Please add a new post if still need help.