[BUGFIX] Reinitialize validation after adding fields to the document 13/41813/4
authorThorsten Boock <tboock@codegy.de>
Wed, 22 Jul 2015 13:27:06 +0000 (15:27 +0200)
committerMarkus Klein <markus.klein@typo3.org>
Wed, 22 Jul 2015 17:00:58 +0000 (19:00 +0200)
The FormEngineValidation must be reinitialized every time new form fields
have been added to the document or their values are never sent to the
server.

Resolves: #68465
Releases: master
Change-Id: I2416aaad60f165841b71fc5029cb12d73ac376a7
Reviewed-on: http://review.typo3.org/41813
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
typo3/sysext/backend/Resources/Public/JavaScript/FormEngineValidation.js
typo3/sysext/backend/Resources/Public/JavaScript/jsfunc.inline.js

index 50fcea5..da07cc9 100644 (file)
@@ -45,14 +45,7 @@ define('TYPO3/CMS/Backend/FormEngineValidation', ['jquery', 'TYPO3/CMS/Backend/F
                $(document).find('.' + FormEngineValidation.errorClass).removeClass(FormEngineValidation.errorClass);
 
                // Initialize input fields
-               $(document).find(FormEngineValidation.inputSelector).each(function() {
-                       var config = $(this).data('formengine-input-params');
-                       var fieldName = config.field;
-                       var $field = $('[name="' + fieldName + '"]');
-                       $field.data('main-field', fieldName);
-                       $field.data('config', config);
-                       FormEngineValidation.initializeInputField(fieldName);
-               }).promise().done(function () {
+               FormEngineValidation.initializeInputFields().promise().done(function () {
                        // Bind to field changes
                        $(document).on('change', FormEngineValidation.rulesSelector, function() {
                                // we need to wait, because the update of the select fields needs some time
@@ -82,6 +75,26 @@ define('TYPO3/CMS/Backend/FormEngineValidation', ['jquery', 'TYPO3/CMS/Backend/F
        };
 
        /**
+        * initialize all input fields
+        *
+        * @returns {*|jQuery}
+        */
+       FormEngineValidation.initializeInputFields = function() {
+               return $(document).find(FormEngineValidation.inputSelector).each(function() {
+                       var config = $(this).data('formengine-input-params');
+                       var fieldName = config.field;
+                       var $field = $('[name="' + fieldName + '"]');
+
+                       // ignore fields which already have been initialized
+                       if ($field.data('main-field') === undefined) {
+                               $field.data('main-field', fieldName);
+                               $field.data('config', config);
+                               FormEngineValidation.initializeInputField(fieldName);
+                       }
+               });
+       };
+
+       /**
         *
         * @param {number} mode
         */
index a97e90d..89ed858 100644 (file)
@@ -287,6 +287,7 @@ var inline = {
                                });
                        }
                        TYPO3.FormEngine.reinitialize();
+                       TYPO3.FormEngine.Validation.initializeInputFields();
                        TYPO3.FormEngine.Validation.validate();
                }
        },