diff --git a/Resources/Public/JavaScript/ImageAlternative.js b/Resources/Public/JavaScript/ImageAlternative.js index 758d523..45fa0a2 100644 --- a/Resources/Public/JavaScript/ImageAlternative.js +++ b/Resources/Public/JavaScript/ImageAlternative.js @@ -1,33 +1,39 @@ /** - * Module: TYPO3/CMS/Hafenk/ImageAlternative + * Module: TYPO3/CMS/T3imagealternative/ImageAlternative */ define([ 'jquery', 'TYPO3/CMS/Backend/FormEngineValidation' ], function($, FormEngineValidation) { - var ImageAlternative = { - foo: 'bar' - }; + var ImageAlternative = {}; ImageAlternative.initialize = function() { $(document).find(FormEngineValidation.inputSelector).each(function() { if($(this).attr('data-formengine-validation-rules').indexOf('ImageAlternative') > -1) { ImageAlternative.initializeInput(this); - } - $(document).on('change', FormEngineValidation.rulesSelector, function() { - ImageAlternative.initializeInput(this); - }); + $(document).on('change', FormEngineValidation.rulesSelector, function() { + ImageAlternative.initializeInput(this); + }); + } }); }; ImageAlternative.initializeInput = function($element) { - if ($element.placeholder === '' && $element.value === '') { - $element.closest(FormEngineValidation.markerSelector).classList.toggle(FormEngineValidation.errorClass, true); - FormEngineValidation.markParentTab($($element), isValid); + var markParent = false; - $(document).trigger('t3-formengine-postfieldvalidation'); + // Here we could do an actualy check for the sys_file_metadata table + // like in the evaluation class + if ($element.placeholder === '' && $element.value === '') { + var markParent = true; } + + // Inspired by FormEngineValidation + const isValid = !markParent; + $element.closest(FormEngineValidation.markerSelector).classList.toggle(FormEngineValidation.errorClass, !isValid); + FormEngineValidation.markParentTab($($element), isValid); + + $(document).trigger('t3-formengine-postfieldvalidation'); }; ImageAlternative.initialize(); diff --git a/ext_localconf.php b/ext_localconf.php index 9193467..75cc00c 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -6,5 +6,14 @@ $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][\VV\T3imagealternative\Evaluation\ImageAlternative::class] = ''; +// Maybe use the $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['RequireJS']['postInitializationModules'] +// See PageRenderer->computeRequireJsConfig (\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Page\PageRenderer::class)) - ->loadRequireJsModule('TYPO3/CMS/T3imagealternative/ImageAlternative'); + ->addInlineSettingArray( + 'RequireJS.PostInitializationModules', + [ + 'TYPO3/CMS/Backend/FormEngine' => [ + 'TYPO3/CMS/T3imagealternative/ImageAlternative' + ] + ] + );