[BUGFIX] Remember not rendered checkboxes in TCA treeSelect 12/47812/3
authorFrans Saris <franssaris@gmail.com>
Wed, 20 Apr 2016 13:45:10 +0000 (15:45 +0200)
committerFrans Saris <franssaris@gmail.com>
Mon, 25 Apr 2016 13:00:12 +0000 (15:00 +0200)
When you have a select field of rendertype selectTree it looses the
selected values of the not rendered checkboxes.

This changes makes sure that also the not rendered values are kept.

Change-Id: I8649e83c56a0265a7de069ef9654ed13b90b3239
Resolves: #75519
Releases: master, 7.6, 6.2
Reviewed-on: https://review.typo3.org/47812
Tested-by: Philipp Gampe <philipp.gampe@typo3.org>
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Reviewed-by: Susanne Moog <typo3@susannemoog.de>
Tested-by: Susanne Moog <typo3@susannemoog.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/backend/Resources/Public/JavaScript/tree.js

index ffeecce..a139e69 100644 (file)
@@ -69,6 +69,14 @@ Ext.extend(TYPO3.Components.Tree.StandardTree, Ext.tree.TreePanel, {
                        }
                });
 
+               // prepare hidden input field (make sure only comma separated uids are present)
+               var selected = Ext.fly('treeinput' + this.id).dom.value.split(',');
+               for (var i = 0; i < selected.length; i++) {
+                       var value = selected[i].split('|');
+                       selected[i] = value[0];
+               }
+               Ext.fly('treeinput' + this.id).dom.value = selected.join(',');
+
                Ext.apply(this, {
                        tbar: this.initialConfig.showHeader ? TYPO3.Components.Tree.Toolbar([], this) : null
                });
@@ -188,7 +196,8 @@ TYPO3.Components.Tree.EmptySelectionModel = new Ext.tree.DefaultSelectionModel({
 
 TYPO3.Components.Tree.TcaCheckChangeHandler = function(checkedNode, checked) {
        var exclusiveKeys = this.tcaExclusiveKeys.split(','),
-               uid = '' + checkedNode.attributes.uid;
+               uid = '' + checkedNode.attributes.uid,
+               selected = Ext.fly('treeinput' + this.id).dom.value.split(',');
 
        this.suspendEvents();
 
@@ -232,12 +241,20 @@ TYPO3.Components.Tree.TcaCheckChangeHandler = function(checkedNode, checked) {
                        node.ui.toggleCheck(checkedNode.attributes.checked);
                })
        }
-       var selected = [];
+
        this.root.cascade(function(node) {
                if (node.ui.isChecked()) {
-                       selected.push(node.attributes.uid);
+                       if (selected.indexOf(node.attributes.uid) < 0) {
+                               selected.push(node.attributes.uid)
+                       }
+               } else {
+                       var index = selected.indexOf(node.attributes.uid);
+                       if (index >= 0) {
+                               selected.splice(index, 1);
+                       }
                }
        });
+
        this.countSelectedNodes = selected.length;
        Ext.fly('treeinput' + this.id).dom.value = selected.join(',');
        eval(this.onChange);