CR/LF not visible in TextArea List View

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
abmd82
User
Posts: 7

CR/LF not visible in TextArea List View

Post by abmd82 »

There are text fields containing longer text with CR/LF. But they are no visible in list view. When I click on inline edit, the breaks become visible. But I need them in list view for readability.
The setting "Replace CR +LF by <br>" seems to have no effect and I read in manual, that this does only work for memo fields.
What am I missing?


arbei
User
Posts: 9284

Post by arbei »

If your field values use "\r" as line breaks, you may use Row_Rendered server event (see Server Events and Client Scripts in the help file), e.g.

$this->MyField->ViewValue = str_replace(["\\r\\n", "\\r"], "<br>", $this->MyField->ViewValue);

abmd82
User
Posts: 7

Post by abmd82 »

Okay, just created a complete new project with the exact same view. Guess what... your code works in this project. I think I have to make some comparisons between the projects to find the difference. Strange!

Thank you for your help :) When I find out, what caused the error, I will post it here.


abmd82
User
Posts: 7

Post by abmd82 »

Found the problem: I limited the length of the field to 2000 chars. When this value is set, the function has no effect.

Tried it for- and backward and it's reproducible.

View Tag -> Format-> "Max length (List page)"


arbei
User
Posts: 9284

Post by arbei »

That is because the "Max length (List page)" option tries to show long data by a one-line short text like "Some long string..." in a table column in the List page, it will remove the white spaces first, but in your particular case you use a rather large number 2000 so you may still want line breaks. In such case you may disable "Max length (List page)", enable "Replace CR +LF by <br>" and use Row_Rendered server event to truncate, e.g.

$this->MyField->ViewValue = TruncateMemo($this->MyField->ViewValue, 2000);

philmills
User
Posts: 535

Post by philmills »

I found you can use CSS to force linebreaks to be obeyed using this in row_rendered

$this->MyField->ViewValue = "<span style='white-space: pre-wrap;'>".$this->MyField->CurrentValue."</span>";

philmills
User
Posts: 535

Post by philmills »

How can i get dompdf to obey CR/LF ?
according to this css white-space: pre-line should work, but it doesn't:
https://github.com/dompdf/dompdf/issues/1814

any ideas?


arbei
User
Posts: 9284

Post by arbei »

PDF is exported by ExportPdf class, you should customize the class (see viewtopic.php?t=50364) or the ewpdf.css.


philmills
User
Posts: 535

Post by philmills »

Adding white-space: pre-wrap; to .ew-table td in ew.pdf fixed it.

.ew-table td, .ew-table th {
  padding: 3px;
  border: 0.5px solid;
  border-color: #DEE2E6;
  white-space: pre-wrap;
}

Is there a way to set this in user styles, so it doesn't get overwritten when generating files ?


arbei
User
Posts: 9284

Post by arbei »

You may copy the original dompdf extension and customize it as your own. Also read Making Extensions.


philmills
User
Posts: 535

Post by philmills »

Can I redefine like this in user styles?

.ew-export-table td {
  border: 1px solid;
  border-color: #DEE2E6;
}

Post Reply