[BUGFIX] JS: Invert dependency definition for FormEngine and Validation 07/52207/3
authorMarkus Klein <markus.klein@typo3.org>
Mon, 27 Mar 2017 13:45:58 +0000 (15:45 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Tue, 28 Mar 2017 09:36:31 +0000 (11:36 +0200)
FormEngineValidation is meant as integral part of FormEngine.
The current dependency definition is inverted, such that FormEngine
now depends on FormEngineValidation and not the other way around.
Note that FormEngineValidation does not need any other feature
of FormEngine, so this is safe.

This solves a possible race condition with other modules.

Releases: master, 7.6
Resolves: #80459
Change-Id: Ie2cb9dd90220b37a98bc8e3ca174fd074488cc8d
Reviewed-on: https://review.typo3.org/52207
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/backend/Classes/Form/FormResultCompiler.php
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine.js
typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js

index 07bfe38..7fab56a 100644 (file)
@@ -214,10 +214,8 @@ class FormResultCompiler
         // load the main module for FormEngine with all important JS functions
         $this->requireJsModules['TYPO3/CMS/Backend/FormEngine'] = 'function(FormEngine) {
                        FormEngine.setBrowserUrl(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('wizard_element_browser')) . ');
-               }';
-        $this->requireJsModules['TYPO3/CMS/Backend/FormEngineValidation'] = 'function(FormEngineValidation) {
-                       FormEngineValidation.setUsMode(' . ($GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? '1' : '0') . ');
-                       FormEngineValidation.registerReady();
+                       FormEngine.Validation.setUsMode(' . ($GLOBALS['TYPO3_CONF_VARS']['SYS']['USdateFormat'] ? '1' : '0') . ');
+                       FormEngine.Validation.registerReady();
                }';
 
         $pageRenderer = $this->getPageRenderer();
index c6d0ed3..6b447ca 100644 (file)
  */
 
 // add legacy functions to be accessible in the global scope
-var setFormValueOpenBrowser
-       ,setFormValueFromBrowseWin
-       ,setHiddenFromList
-       ,setFormValueManipulate
-       ,setFormValue_getFObj;
+var setFormValueOpenBrowser,
+       setFormValueFromBrowseWin,
+       setHiddenFromList,
+       setFormValueManipulate,
+       setFormValue_getFObj;
 
 /**
  * Module: TYPO3/CMS/Backend/FormEngine
  */
 define(['jquery',
+               'TYPO3/CMS/Backend/FormEngineValidation',
                'TYPO3/CMS/Backend/Modal',
                'TYPO3/CMS/Backend/Severity'
-          ], function ($, Modal, Severity) {
+          ], function ($, FormEngineValidation, Modal, Severity) {
 
        /**
         *
-        * @type {{formName: *, backPath: *, openedPopupWindow: null, legacyFieldChangedCb: Function, browserUrl: string}}
+        * @type {{Validation: object, formName: *, backPath: *, openedPopupWindow: window, legacyFieldChangedCb: Function, browserUrl: string}}
         * @exports TYPO3/CMS/Backend/FormEngine
         */
        var FormEngine = {
-               formName: TYPO3.settings.FormEngine.formName
-               ,backPath: TYPO3.settings.FormEngine.backPath
-               ,openedPopupWindow: null
-               ,legacyFieldChangedCb: function() { !$.isFunction(TYPO3.settings.FormEngine.legacyFieldChangedCb) || TYPO3.settings.FormEngine.legacyFieldChangedCb(); }
-               ,browserUrl: ''
+               Validation: FormEngineValidation,
+               formName: TYPO3.settings.FormEngine.formName,
+               backPath: TYPO3.settings.FormEngine.backPath,
+               openedPopupWindow: null,
+               legacyFieldChangedCb: function() { !$.isFunction(TYPO3.settings.FormEngine.legacyFieldChangedCb) || TYPO3.settings.FormEngine.legacyFieldChangedCb(); },
+               browserUrl: ''
        };
 
        /**
@@ -91,10 +93,12 @@ define(['jquery',
                exclusiveValues = String(exclusiveValues);
 
                var $fieldEl,
-                       $originalFieldEl = $fieldEl = FormEngine.getFieldElement(fieldName),
+                       $originalFieldEl,
                        isMultiple = false,
                        isList = false;
 
+               $originalFieldEl = $fieldEl = FormEngine.getFieldElement(fieldName);
+
                if ($originalFieldEl.length === 0 || value === '--div--') {
                        return;
                }
index 0321f18..4ffa0aa 100644 (file)
@@ -16,7 +16,7 @@
  * Contains all JS functions related to TYPO3 TCEforms/FormEngineValidation
  * @internal
  */
-define(['jquery', 'TYPO3/CMS/Backend/FormEngine'], function ($, FormEngine) {
+define(['jquery'], function ($) {
 
        /**
         * The main FormEngineValidation object
@@ -1064,7 +1064,5 @@ define(['jquery', 'TYPO3/CMS/Backend/FormEngine'], function ($, FormEngine) {
                });
        };
 
-       FormEngine.Validation = FormEngineValidation;
-
-       return FormEngine.Validation;
+       return FormEngineValidation;
 });