Issue Bug Closed

#106921Inline JS no longer available in custom eval

Davide Alghi 06/22/25, 07:16 updated 11/11/25, 12:33

Description

In T3 13, returnFieldJS() function returning JS in text format is no longer possible. here
https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.4/Deprecation-100587-DeprecateFormEngineAdditionalJavaScriptPostAndCustomEvalInlineJavaScript.html#example
Documentation needs updating, here
https://docs.typo3.org/m/typo3/reference-tca/13.4/en-us/ColumnsConfig/Type/Input/#columns-input-eval-custom
( details in attached screenshot )

============================================================================
*Adding an example might be helpful (it evaluates a double to 5 decimal places):*

myextkey/Configuration/JavaScriptModules.php

return [
    'dependencies' => [],
    'tags' => [],
    'imports' => [
        '@pad/myextkey/' => [
            'path' => 'EXT:myextkey/Resources/Public/JavaScript/',
        ],
    ],
];

myextkey/Classes/TcaEvaluation/Double5.php

namespace PAD\Myextkey\TcaEvaluation;

use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;

/**
 * Double5 TCA evaluation function class
 * Evaluates and formats a 5-decimals float value
 */
class Double5
{
    /**
     * JavaScript code for client side validation/evaluation
     *
     * @param none
     * @return JavaScriptModuleInstruction
     */
    public function returnFieldJS(): JavaScriptModuleInstruction
    {
        return JavaScriptModuleInstruction::create('@pad/myextkey/Backend/FormEngine/TcaEvaluation/Double5Evaluation.js', 'Double5Evaluation');
    }

    /**
     * Server-side validation/evaluation on saving the record
     *
     * @param string $value The field value to be evaluated
     * @param string $is_in The "is_in" value of the field configuration from TCA
     * @param bool $set Boolean defining if the value is written to the database or not.
     * @return float Evaluated field value
     */
    public function evaluateFieldValue($value, $is_in, &$set): float
    {
        $value = floatval($value);
        if (is_float($value)) {
            $value = round($value, 5);
        } else {
            $value = 0.00000;
        }
        return $value;
    }

    /**
     * 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): string
    {
        $value = floatval($parameters['value']);
        return number_format($value, 5);
    }
}

myextkey/Resources/Public/JavaScript/Backend/FormEngine/TcaEvaluation/Double5Evaluation.js

import FormEngineValidation from '@typo3/backend/form-engine-validation.js';

export class Double5Evaluation {

    static registerCustomEvaluation(name) {
        FormEngineValidation.registerCustomEvaluation(name, Double5Evaluation.double5Validation);
    }

    static double5Validation(value) {
        value = isNaN(parseFloat(value)) ? 0 : parseFloat(value);
        value = value.toFixed(5);
        return value.toString();
    }
}

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.