[FOLLOWUP][TASK] Hide selected items in multipleSideBySide 07/48107/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Tue, 10 May 2016 11:53:18 +0000 (13:53 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 12 May 2016 16:03:03 +0000 (18:03 +0200)
The original patch introduced some regressions which are fixed now:

- Deletion of multiple items works correctly now
- Inserting items by the Element Browser does not throw an error anymore

Resolves: #76071
Releases: master, 7.6
Change-Id: Ie16a1d404c2f12e6c952dc5022caff08ec6af171
Reviewed-on: https://review.typo3.org/48107
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine.js

index 9136d30..bbdcb78 100644 (file)
@@ -130,20 +130,25 @@ define(['jquery',
 
                        // Clear elements if exclusive values are found
                        if (exclusiveValues) {
-                               var $optionSelect = $optionEl.closest('select');
+                               var reenableOptions = false;
+
                                var m = new RegExp('(^|,)' + value + '($|,)');
                                // the new value is exclusive => remove all existing values
                                if (exclusiveValues.match(m)) {
                                        $fieldEl.empty();
-                                       $optionSelect.find('[disabled]').removeClass('hidden').prop('disabled', false);
+                                       reenableOptions = true;
                                } else if ($fieldEl.children('option').length == 1) {
                                        // there is an old value and it was exclusive => it has to be removed
                                        m = new RegExp("(^|,)" + $fieldEl.children('option').prop('value') + "($|,)");
                                        if (exclusiveValues.match(m)) {
                                                $fieldEl.empty();
-                                               $optionSelect.find('[disabled]').removeClass('hidden').prop('disabled', false);
+                                               reenableOptions = true;
                                        }
                                }
+
+                               if (reenableOptions && typeof $optionEl !== 'undefined') {
+                                       $optionEl.closest('select').find('[disabled]').removeClass('hidden').prop('disabled', false)
+                               }
                        }
 
                        // Inserting the new element
@@ -159,7 +164,7 @@ define(['jquery',
                                        }
                                });
 
-                               if (addNewValue) {
+                               if (addNewValue && typeof $optionEl !== 'undefined') {
                                        $optionEl.addClass('hidden').prop('disabled', true);
                                }
                        }
@@ -563,10 +568,12 @@ define(['jquery',
        FormEngine.removeOption = function($fieldEl, $availableFieldEl) {
                var $selected = $fieldEl.find(':selected');
 
-               $availableFieldEl
-                       .find('option[value="' + $selected.attr('value') + '"]')
-                       .removeClass('hidden')
-                       .prop('disabled', false);
+               $selected.each(function() {
+                       $availableFieldEl
+                               .find('option[value="' + $(this).attr('value') + '"]')
+                               .removeClass('hidden')
+                               .prop('disabled', false);
+               });
 
                // remove the selected options
                $selected.remove();