[BUGFIX] EXT:form - Avoid JavaScript errors 38/52338/3
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Mon, 3 Apr 2017 12:40:08 +0000 (14:40 +0200)
committerBenni Mack <benni@typo3.org>
Fri, 7 Apr 2017 14:58:12 +0000 (16:58 +0200)
Avoid JavaScript errors especially if you try to remove a
"Required field" validator from an element which has no validator
select list (like a checkbox).

Resolves: #80657
Releases: master
Change-Id: Id117250ad131a2367c87fc39b6fdb698d84cd421
Reviewed-on: https://review.typo3.org/52338
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Andreas Steiger <typo3@andreassteiger.de>
Tested-by: Andreas Steiger <typo3@andreassteiger.de>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/form/Configuration/Yaml/FormEditorSetup.yaml
typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor.js
typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor/InspectorComponent.js

index cf24f02..b5de05a 100644 (file)
@@ -430,6 +430,10 @@ TYPO3:
                 group: select
                 groupSorting: 500
                 iconIdentifier: 't3-form-icon-multi-checkbox'
+                editors:
+                  800:
+                    propertyPath: null
+                    propertyValue: null
 
             MultiSelect:
               formEditor:
index 9f620eb..8711205 100644 (file)
@@ -454,11 +454,14 @@ define(['jquery',
                 assert(getUtility().isNonEmptyString(collectionName), 'Invalid parameter "collectionName"', 1475378556);
 
                 formElementDefinition = getFormElementDefinitionByType(formElement.get('type'));
-                collection = formElementDefinition['propertyCollections'][collectionName];
-                assert(!getUtility().isUndefinedOrNull(collection), 'Invalid collection name "' + collectionName + '"', 1475446108);
-                collectionElement = _getRepository().findCollectionElementByIdentifierPath(collectionElementIdentifier, collection);
-
-                return $.extend(true, {}, collectionElement);
+                if (!getUtility().isUndefinedOrNull(formElementDefinition['propertyCollections'])) {
+                    collection = formElementDefinition['propertyCollections'][collectionName];
+                    assert(!getUtility().isUndefinedOrNull(collection), 'Invalid collection name "' + collectionName + '"', 1475446108);
+                    collectionElement = _getRepository().findCollectionElementByIdentifierPath(collectionElementIdentifier, collection);
+                    return $.extend(true, {}, collectionElement);
+                } else {
+                    return {};
+                }
             };
 
             /**
index e7fb281..c82a513 100644 (file)
@@ -1713,8 +1713,6 @@ define(['jquery',
          * @throws 1475417094
          * @throws 1475417095
          * @throws 1475417096
-         * @throws 1489319751
-         * @throws 1489319752
          */
         function renderRequiredValidatorEditor(editorConfiguration, editorHtml, collectionElementIdentifier, collectionName) {
             var propertyPath, propertyValue, validatorIdentifier;
@@ -1738,27 +1736,25 @@ define(['jquery',
                 'Invalid configuration "label"',
                 1475417096
             );
-            assert(
-                getUtility().isNonEmptyString(editorConfiguration['propertyPath']),
-                'Invalid configuration "propertyPath"',
-                1489319751
-            );
-            assert(
-                getUtility().isNonEmptyString(editorConfiguration['propertyValue']),
-                'Invalid configuration "propertyValue"',
-                1489319752
-            );
 
             validatorIdentifier = editorConfiguration['validatorIdentifier'];
             getHelper().getTemplatePropertyDomElement('label', editorHtml).append(editorConfiguration['label']);
 
-            propertyPath = getFormEditorApp()
-                .buildPropertyPath(editorConfiguration['propertyPath'], collectionElementIdentifier, collectionName);
-            propertyValue = editorConfiguration['propertyValue'];
+            if (getUtility().isNonEmptyString(editorConfiguration['propertyPath'])) {
+                propertyPath = getFormEditorApp()
+                    .buildPropertyPath(editorConfiguration['propertyPath'], collectionElementIdentifier, collectionName);
+            }
+            if (getUtility().isNonEmptyString(editorConfiguration['propertyValue'])) {
+                propertyValue = editorConfiguration['propertyValue'];
+            } else {
+                propertyValue = '';
+            }
 
             if (-1 !== getFormEditorApp().getIndexFromPropertyCollectionElement(validatorIdentifier, 'validators')) {
                 $('input[type="checkbox"]', $(editorHtml)).prop('checked', true);
-                getCurrentlySelectedFormElement().set(propertyPath, propertyValue);
+                if (getUtility().isNonEmptyString(propertyPath)) {
+                    getCurrentlySelectedFormElement().set(propertyPath, propertyValue);
+                }
             }
 
             $('input[type="checkbox"]', $(editorHtml)).on('change', function() {
@@ -1767,13 +1763,18 @@ define(['jquery',
                         'view/inspector/collectionElement/new/selected',
                         [validatorIdentifier, 'validators']
                     );
-                    getCurrentlySelectedFormElement().set(propertyPath, propertyValue);
+
+                    if (getUtility().isNonEmptyString(propertyPath)) {
+                        getCurrentlySelectedFormElement().set(propertyPath, propertyValue);
+                    }
                 } else {
                     getPublisherSubscriber().publish(
                         'view/inspector/removeCollectionElement/perform',
                         [validatorIdentifier, 'validators']
                     );
-                    getCurrentlySelectedFormElement().unset(propertyPath);
+                    if (getUtility().isNonEmptyString(propertyPath)) {
+                        getCurrentlySelectedFormElement().unset(propertyPath);
+                    }
                 }
             });
         };