Strategies for preserving line breaks in a database

I am currently utilizing TypeORM for managing my database with NestJS framework on the server side and Vue.js on the client side.

Within the settings, I need to input a large text and ensure that line breaks (\n) are saved in the database.

Here's a snippet of my code:

Vue textarea

<b-form-textarea 
       style="white-space: pre-line"
       v-model="projectShortDesc"
       class="mt-2 description-input"></b-form-textarea>

Afterward, I send this data from

v-model="projectShortDesc"
to my server.

@Column({
    type: 'varchar',
    length: 150,
    nullable: true
})
shortDescription: string;

To save it, I use the following method:

project.shortDescription = descFromVue;
await this.conn.getRepository(Project).save(project);

Could someone please advise me on how to store '\n' in the database when pressing enter in the description field?

Many thanks for any assistance provided!

Answer №1

If you want to insert line breaks in a MySQL database, remember to add /n whenever the user presses the enter key in the text box. This simple trick can make it easier for you.

<template>
  <div id="app">
     <b-form-textarea 
       style="white-space: pre-line"
       v-model="projectShortDesc"
       class="mt-2 description-input"
        v-on:keyup.enter="onEnter">
      </b-form-textarea>
  </div>
</template>

<script>
export default {
 name: "App",
 methods: {
  onEnter() {
    this.projectShortDesc.apend('/n')
    },
 },
};
</script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the procedure for modifying the height of a button in HTML?

I wanted to add a flashing "Contact Us" button to the menu bar of my website to immediately attract people's attention when they visit. Here is the javascript code I used: <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&g ...

Problems Arising from the Combination of Django and External JavaScript

I am currently working on a project that uses Django 1.11 and JavaScript, but I am encountering an issue. The JavaScript code works fine when run within the HTML file, as it successfully loads the JSON data. However, when I move everything to the static fo ...

Encountering an issue with react-dom that needs to be resolved

After updating my node and npm installations, I encountered an error when trying to run my project. Specifically, I am using "react": "^0.13.3" and "react-dom": "0.14.0-beta3" npm WARN unmet dependency /Users/hilarl/Desktop/client/node_modules/react-do ...

Tips for choosing a codemirror instance in vue

How can I select one of multiple codemirror instances when I have tried var basicEditor = VueCodemirror.CodeMirror($('#basic').get(0)); without success? Below is the code snippet in question: Vue.use(window.VueCodemirror); Vue.component(' ...

Set up ExpressJS to utilize port 3000 for the server

I am working on an app where the backend is currently running on localhost:8000, but I need it to run on port 3000. Specifically, I am using an express server for this example. How can I configure it to run on the desired port? Below is my current server. ...

Approximating Values with JavaScript in Selenium

Hi there! I've been exploring selenium IDE and encountered an issue related to asserting an approximate value. My challenge is to validate a numeric value within an element identified by its id, where the value is in numerical format with commas separ ...

Problem with integrating MEAN stack and bootstrap using bower

Recently, I've been delving into new methods of development and stumbled upon the MEAN stack. You can learn more about it here - After setting up Mongo, Node (and npm, among others) following the instructions on the website, I encountered a problem w ...

experiencing deployment issues with the openai npm package

I encountered an unexpected error in my backend while trying to deploy. This error only started appearing after I installed the openai package. Although my node version is 20, which should support node:fs, it seems that the module 'node:fs' cann ...

Having issues with the functionality of jQuery. It needs to be able to override existing

I am trying to make it so that if yes2 == none, the element with class .bottomandroid is removed and instead, the element with class .cta is displayed. However, it doesn't seem to be working as expected. How can I fix this issue? else if (isAndroid) ...

What steps are necessary to create an npm package utilizing three.js without any dependencies?

I have a challenge - I am trying to create an npm package that generates procedural objects for three.js. The issue I'm facing is how to properly include three.js in my code. I attempted to establish a dependency and use something like const THREE = r ...

Issue with stacking layers

Currently facing a simple issue that I'm struggling to resolve. I'm integrating some code into my website, but the image is set as a background layer, preventing it from appearing above other elements on the page. Is there a way to embed the bac ...

Tips for transferring a JSON object from an HTML document to a JavaScript file

Here is the code snippet: <script id="product-listing" type="x-handlebars-template"> {{#each productsInCart}} <tr> <td> <div class="imageDiv"> <img ...

When using TypeScript and Material UI, it is important to assign a value to boolean attributes

Trying to implement Material UI code with Typescript for a DisplayCard component, but encountering an error message: (34,23): Value must be set for boolean attributes. The challenge lies in identifying which attribute value is missing... Here is the samp ...

The if statement remains active without being disabled

Currently, I am working on coding a bot for my school that includes a feature allowing students to talk in a voice channel if they send a specific message and the teacher reacts with a specific emoji. Below is the code snippet: client.on('message&apos ...

Tactile interactions on iPhone

My goal is to create an off-canvas menu that can be opened with touch events in a systematic way. It functions perfectly in my browser when I click and drag on the body to reveal the menu. However, it encounters a problem on the iPhone. The error message ...

Facing a Challenge with Textures in ThreeJS ShaderMaterial

I seem to be having trouble with my texture not being displayed properly in three.js r71. The plane is just showing up black and I can't figure out what's wrong with my ShaderMaterial. I could really use another set of eyes to help me identify th ...

Is there a way to utilize javascript std input/output in repl.it effectively?

I created a straightforward program that calculates the factorial of a specified number, and I am interested in running it on repl.it. During its execution, I would like to interact with standard input and output through the command line. Is there a way ...

Tips for securely concealing login details during an API call

As a newcomer to the world of Javascript and Vue.js, I am eager to expand my knowledge in these areas. However, I have encountered an issue while attempting to call an API login that exposes a password in the request payload. It seems quite insecure to ha ...

A method for dividing a string into separate characters and organizing them into an array of JSON objects

I have a collection of JSON objects with a fixed key 'type' and additional keys based on the type. Here is an example of how it looks: theArray = [ { "type": "text", "text": "= SUM(" ...

The left margin of the Bootstrap 12 column grid is not aligned correctly

Currently, I am utilizing Bootstrap in conjunction with Vue within an App.vue file. One issue I have encountered is the excessive empty space on both the left and right sides when using Bootstrap. An image has been provided below for reference. I followed ...