Skip to content

Commit

Permalink
Add JavaScriptModuleInstruction to custom email (#1213)
Browse files Browse the repository at this point in the history
  • Loading branch information
sypets authored Jan 24, 2025
1 parent 96a8d14 commit 54c7313
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Documentation/ColumnsConfig/Type/Input/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ Custom eval rules
You can supply own form evaluations in an extension by creating a class with three functions, one which returns
the JavaScript code for client side validation called `returnFieldJS()` and two for the server side:
`deevaluateFieldValue()` called when opening the record and `evaluateFieldValue()` called for validation when
saving the record:
saving the record.

.. hint::

See EXT:redirects :php:`\TYPO3\CMS\Redirects\Evaluation\SourceHost` for a
working example. For more information about adding JavaScript modules
see :ref:`ES6 in the TYPO3 Backend <t3coreapi:backend-javascript-es6>`.

:file:`EXT:extension/Classes/Evaluation/ExampleEvaluation.php`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace MVendor\MyExtension\Evaluation;

use TYPO3\CMS\Core\Page\JavaScriptModuleInstruction;

/**
* Class for field value validation/evaluation to be used in 'eval' of TCA
*/
Expand All @@ -10,11 +12,17 @@ class ExampleEvaluation
/**
* JavaScript code for client side validation/evaluation
*
* @return string JavaScript code for client side validation/evaluation
* @return string|JavaScriptModuleInstruction JavaScript code for client side validation/evaluation
*/
public function returnFieldJS()
{
return 'return value + " [added by JavaScript on field blur]";';
// you can return JavaScript code directly:
//return 'return value + " [added by JavaScript on field blur]";';

// or you can use JavaScriptModuleInstruction.
// In this case you should add your JavaScript modules using
// Configuration/JavaScriptModules.php
return JavaScriptModuleInstruction::create('@myvendor/myextension/example-evaluation.js', 'FormEngineEvaluation');
}

/**
Expand Down

0 comments on commit 54c7313

Please sign in to comment.