Issue Bug Closed

#82705Leading line breaks in tca fields of type text are saved, but are not shown when data record is edited in TYPO3 backend

Michael Giesler 10/09/17, 10:18 updated 11/06/26, 11:16

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.

Reviews 1

History 5

  1. Christian Kuhn commented <span data-processor="relativetime" data-value="2017-11-01T16:45:33+00:00" > 11/01/17, 16:45 </span>

    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).

  2. Markus Mächler commented <span data-processor="relativetime" data-value="2020-02-07T15:26:51+00:00" > 02/07/20, 15:26 </span>

    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:&lt;/p&gt; &lt;p&gt;

    <textarea>No leading new line</textarea>
    <textarea>
    One leading new line</textarea>
    <textarea>
    
    Two leading new lines</textarea>
    &lt;/p&gt; &lt;p&gt;&lt;a href="https://jsfiddle.net/humqe95j/2/" target="_blank" rel="noreferrer"&gt;https://jsfiddle.net/humqe95j/2/&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The right way to solve this would be for TYPO3 to always insert one leading newline for all &lt;textarea&gt; 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 &lt;textarea&gt;, one is trimmed away by the browser and the second one is displayed. Like this we also only save one newline to the database.&lt;/p&gt; &lt;p&gt;I created an eval (only implementing deevaluate) to workaround this:&lt;/p&gt; &lt;p&gt;&lt;strong&gt;NewlineEvaluation.php&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;
    <?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'];
        }
    }
    &lt;/p&gt; &lt;p&gt;&lt;strong&gt;ext_localconf.php&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;
    $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals']['Your\\Ext\\Eval\\NewlineEvaluation'] = '';
    &lt;/p&gt; &lt;p&gt;&lt;strong&gt;TCA (e.g. Configuration/TCA/Overrides/tt_content.php header)&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;
    $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';
    &lt;/p&gt;</textarea>

  3. Benni Mack commented and changed status New Closed <span data-processor="relativetime" data-value="2026-11-06T11:16:05+00:00" > 11/06/26, 11:16 </span>

    Fixed with #94516 (https://review.typo3.org/c/Packages/TYPO3.CMS/+/87217, main + 13.4): FormEngine textareas now prepend the linefeed the HTML parser swallows, so leading line breaks are shown again. Closing as duplicate.