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';