How to remove a line break from a DB entry

I have a DB with text fields that contain line breaks, e.g.

  • 2x Bag Chocolates
  • 2x Cleaning Spray

The problem is I want to be able to compare the Database with what’s being types in a textarea field in a form.
But it doesn’t work as the DB is spread over two lines, and the form displays is different.

I tried the following code, but it doesn’t work

<div dmx-show="inp_pck_description1.value.replace('\n', '')==pck_description.replace('\n', ' ')"><i class="fas fa-check text-green"></i></div>

Isn’t the strip tags formatter helpful in this case?

<div dmx-show="inp_pck_description1.value.stripTags() == pck_description.stripTags()">
    <i class="fas fa-check text-green"></i>
</div>

I am not sure why its not working. In the DB dynamic field value, its displayed over two lines. The textarea form field uses a class
.formatted-text {
white-space: pre-line;
}

wondering if thats causing the issue.

Can you maybe explain the logic here? What are you trying to achieve exactly?

I want to compare the text in the DB field (which is broken over two lines) with the text being entered in a form field textarea, and if its the same a green tick is displayed

But what is your purpose there? Why is this check required - what’s the workflow on the page?

to know which textarea fields need to be saved with editing the text field

Are your textfields not in the same update record form?

You could try adding an escape

.replace('\\n','')

Ok, I tried that, but for some reason it still has a line break

{{pck_description.replace('\\n','')}}

shows

  • 1x Fresh Cream
  • 1x Butter Block

Ok i tested this locally, your expression should be:

<div dmx-show="inp_pck_description1.value.replace('\n', '', false) == pck_description.replace('\r\n', '', false)">
    <i class="fas fa-check text-green"></i>
</div>

But it looks to me you are really overcomplicating this with some unnecessarily complex checks.

1 Like

Excellent. that works!!! Thanks so much