Bug #82705
openLeading line breaks in tca fields of type text are saved, but are not shown when data record is edited in TYPO3 backend
0%
Description
We have a TYPO3 v8 installation and we encountered a bug:
leading line breaks in tca fields of type text are saved to database, but are not shown when data record is edited in TYPO3 backend.
Updated by Susanne Moog about 7 years ago
- Category set to FormEngine aka TCEforms
Updated by Christian Kuhn about 7 years ago
confirmed. html seems to be ok, guess that happens in JS somewhere, but was unable to locate it. it seems per show exactly one line break is removed in front (not at the end).
Updated by Markus Mächler almost 5 years ago
The error does not happen in JS but has to do with how <textarea> is defined in the HTML standard. The leading newline is removed by the browser for "convenience". Please study the following example:
<textarea>No leading new line</textarea>
<textarea>
One leading new line</textarea>
<textarea>
Two leading new lines</textarea>
https://jsfiddle.net/humqe95j/2/
The right way to solve this would be for TYPO3 to always insert one leading newline for all <textarea> fields, because the browser removes this newline by default nothing happens. As soon as a user enters a leading newline there will be two new lines in the <textarea>, one is trimmed away by the browser and the second one is displayed. Like this we also only save one newline to the database.
I created an eval (only implementing deevaluate) to workaround this:
NewlineEvaluation.php
<?php
namespace Your\Ext\Eval;
/**
* See https://forge.typo3.org/issues/82705
*
* @author Markus Mächler <markus.maechler@bithost.ch>
*/
class NewlineEvaluation
{
/**
* Server-side validation/evaluation on opening the record
*
* @param array $parameters Array with key 'value' containing the field value from the database
* @return string Evaluated field value
*/
public function deevaluateFieldValue(array $parameters)
{
return "\n" . $parameters['value'];
}
}
ext_localconf.php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals']['Your\\Ext\\Eval\\NewlineEvaluation'] = '';
TCA (e.g. Configuration/TCA/Overrides/tt_content.php header)
$GLOBALS['TCA']['tt_content']['columns']['header']['config']['type'] = 'text';
$GLOBALS['TCA']['tt_content']['columns']['header']['config']['rows'] = 3;
$GLOBALS['TCA']['tt_content']['columns']['header']['config']['eval'] = 'Your\\Ext\\Eval\\NewlineEvaluation';