Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Commit

Permalink
Improve clientside validation
Browse files Browse the repository at this point in the history
  • Loading branch information
runepiper committed May 31, 2021
1 parent 93c5ba1 commit 949d5b9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
30 changes: 18 additions & 12 deletions Resources/Public/JavaScript/ImageAlternative.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
11 changes: 10 additions & 1 deletion ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
]
);

0 comments on commit 949d5b9

Please sign in to comment.