jsBee
jsBee

Reputation: 413

'\n' being removed from Input field

I am working on dynamic form where I have input and select tag.

  1. enter data and submit.
  2. see entered information on sidebar with edit button
  3. on edit button click : form will render with values
  4. edit data and click on update button to update

what exactly happening :

While click on Edit button : step num. 3 : if input field has data like

I am in first line 
I am in second line
I am in third line

It rendering on form like in step 3 :

I am in first lineI am in second lineI am in third line

Question : 1. Does Input field not allowed new line? 2. If yes, I tried : style="white-space: pre-line; white-space: pre-wrap;" , but not working 3.How to stop being removed '\n' in input field?

Thank you

Upvotes: 1

Views: 1268

Answers (1)

jsBee
jsBee

Reputation: 413

I found solution using:

   // this is for textarea string 
var elementIdName = document.getElementById(key2);
key2Value = (elementIdName && elementIdName.tagName === "TEXTAREA") ?val.replace(/\\n/g, "<br />") : val;

Upvotes: 1

Related Questions