[BUGFIX] Check if field exists when deleting items from `group` field 59/60259/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 15 Mar 2019 13:32:46 +0000 (14:32 +0100)
committerAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 15 Mar 2019 14:00:15 +0000 (15:00 +0100)
Fields of type `group` don't have a visible counterpart as opposed to
`selectMultipleSideBySide`. Thus, we have to check whether such field
exists before trying to interact with that field.

Resolves: #87925
Related: #87324
Releases: master
Change-Id: Ic8608e065b155949d15ab8d576e30f8d7f8d86db
Reviewed-on: https://review.typo3.org/c/60259
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
typo3/sysext/backend/Resources/Private/TypeScript/FormEngine/Element/AbstractSortableSelectItems.ts
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/Element/AbstractSortableSelectItems.js

index b8a4098..8e46d48 100644 (file)
@@ -85,8 +85,10 @@ export abstract class AbstractSortableSelectItems {
   private static removeOption(fieldElement: HTMLSelectElement, availableFieldElement: HTMLSelectElement): void {
     Array.from(fieldElement.querySelectorAll(':checked')).forEach((option: HTMLOptionElement): void => {
       const originalOption = <HTMLOptionElement>availableFieldElement.querySelector('option[value="' + option.value + '"]');
-      originalOption.classList.remove('hidden');
-      originalOption.disabled = false;
+      if (originalOption !== null) {
+        originalOption.classList.remove('hidden');
+        originalOption.disabled = false;
+      }
 
       fieldElement.removeChild(option);
     });
index f1b5e45..5826a91 100644 (file)
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-var __values=this&&this.__values||function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}};define(["require","exports","jquery","TYPO3/CMS/Backend/FormEngine","TYPO3/CMS/Backend/FormEngineValidation"],function(e,t,n,r,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(){this.registerSortableEventHandler=function(t){var i=t.closest(".form-wizards-wrap").querySelector(".form-wizards-items-aside");null!==i&&i.addEventListener("click",function(i){var l;if(null!==(l=i.target.closest(".t3js-btn-option"))){i.preventDefault();var a=l.dataset.fieldname;l.classList.contains("t3js-btn-moveoption-top")?e.moveOptionToTop(t):l.classList.contains("t3js-btn-moveoption-up")?e.moveOptionUp(t):l.classList.contains("t3js-btn-moveoption-down")?e.moveOptionDown(t):l.classList.contains("t3js-btn-moveoption-bottom")?e.moveOptionToBottom(t):l.classList.contains("t3js-btn-removeoption")&&e.removeOption(t,r.getFieldElement(a,"_avail").get(0)),r.updateHiddenFieldValueFromSelect(t,r.getFieldElement(a).get(0)),r.legacyFieldChangedCb(),o.markFieldAsChanged(n(t)),o.validate()}else i.target.matches(".t3js-btn-option")&&(l=i.target)})}}return e.moveOptionToTop=function(e){Array.from(e.querySelectorAll(":checked")).reverse().forEach(function(t){e.insertBefore(t,e.firstElementChild)})},e.moveOptionToBottom=function(e){Array.from(e.querySelectorAll(":checked")).forEach(function(t){e.insertBefore(t,null)})},e.moveOptionUp=function(e){var t,n,r=Array.from(e.children),o=Array.from(e.querySelectorAll(":checked"));try{for(var i=__values(o),l=i.next();!l.done;l=i.next()){var a=l.value;if(0===r.indexOf(a)&&null===a.previousElementSibling)break;e.insertBefore(a,a.previousElementSibling)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}},e.moveOptionDown=function(e){var t,n,r=Array.from(e.children).reverse(),o=Array.from(e.querySelectorAll(":checked")).reverse();try{for(var i=__values(o),l=i.next();!l.done;l=i.next()){var a=l.value;if(0===r.indexOf(a)&&null===a.nextElementSibling)break;e.insertBefore(a,a.nextElementSibling.nextElementSibling)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}},e.removeOption=function(e,t){Array.from(e.querySelectorAll(":checked")).forEach(function(n){var r=t.querySelector('option[value="'+n.value+'"]');r.classList.remove("hidden"),r.disabled=!1,e.removeChild(n)})},e}();t.AbstractSortableSelectItems=i});
\ No newline at end of file
+var __values=this&&this.__values||function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],n=0;return t?t.call(e):{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}};define(["require","exports","jquery","TYPO3/CMS/Backend/FormEngine","TYPO3/CMS/Backend/FormEngineValidation"],function(e,t,n,r,o){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(){this.registerSortableEventHandler=function(t){var i=t.closest(".form-wizards-wrap").querySelector(".form-wizards-items-aside");null!==i&&i.addEventListener("click",function(i){var l;if(null!==(l=i.target.closest(".t3js-btn-option"))){i.preventDefault();var a=l.dataset.fieldname;l.classList.contains("t3js-btn-moveoption-top")?e.moveOptionToTop(t):l.classList.contains("t3js-btn-moveoption-up")?e.moveOptionUp(t):l.classList.contains("t3js-btn-moveoption-down")?e.moveOptionDown(t):l.classList.contains("t3js-btn-moveoption-bottom")?e.moveOptionToBottom(t):l.classList.contains("t3js-btn-removeoption")&&e.removeOption(t,r.getFieldElement(a,"_avail").get(0)),r.updateHiddenFieldValueFromSelect(t,r.getFieldElement(a).get(0)),r.legacyFieldChangedCb(),o.markFieldAsChanged(n(t)),o.validate()}else i.target.matches(".t3js-btn-option")&&(l=i.target)})}}return e.moveOptionToTop=function(e){Array.from(e.querySelectorAll(":checked")).reverse().forEach(function(t){e.insertBefore(t,e.firstElementChild)})},e.moveOptionToBottom=function(e){Array.from(e.querySelectorAll(":checked")).forEach(function(t){e.insertBefore(t,null)})},e.moveOptionUp=function(e){var t,n,r=Array.from(e.children),o=Array.from(e.querySelectorAll(":checked"));try{for(var i=__values(o),l=i.next();!l.done;l=i.next()){var a=l.value;if(0===r.indexOf(a)&&null===a.previousElementSibling)break;e.insertBefore(a,a.previousElementSibling)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}},e.moveOptionDown=function(e){var t,n,r=Array.from(e.children).reverse(),o=Array.from(e.querySelectorAll(":checked")).reverse();try{for(var i=__values(o),l=i.next();!l.done;l=i.next()){var a=l.value;if(0===r.indexOf(a)&&null===a.nextElementSibling)break;e.insertBefore(a,a.nextElementSibling.nextElementSibling)}}catch(e){t={error:e}}finally{try{l&&!l.done&&(n=i.return)&&n.call(i)}finally{if(t)throw t.error}}},e.removeOption=function(e,t){Array.from(e.querySelectorAll(":checked")).forEach(function(n){var r=t.querySelector('option[value="'+n.value+'"]');null!==r&&(r.classList.remove("hidden"),r.disabled=!1),e.removeChild(n)})},e}();t.AbstractSortableSelectItems=i});
\ No newline at end of file