[pve-devel] [PATCH manager 2/2] fix combogrid multiselect bug

Dominik Csapak d.csapak at proxmox.com
Tue Apr 26 11:32:44 CEST 2016


this fixes a nasty combogrid/multiselect/storeload bug
in which the value of a combogrid gets set to a string instead
of an array, under certain circumstances

we add a pseudo valuefield where we need, and throw an
error in the combogrid initcomponent when this specific
configuration is detected

details are in the comment in the combogrid class, above
the throw statement

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 www/manager6/form/ComboGrid.js     | 26 ++++++++++++++++++++++++++
 www/manager6/form/GroupSelector.js | 11 +++++++++--
 www/manager6/form/NodeSelector.js  | 10 ++++++++--
 3 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/www/manager6/form/ComboGrid.js b/www/manager6/form/ComboGrid.js
index 33f3059..00e9bc7 100644
--- a/www/manager6/form/ComboGrid.js
+++ b/www/manager6/form/ComboGrid.js
@@ -255,6 +255,32 @@ Ext.define('PVE.form.ComboGrid', {
             me.createPicker();
         }
 
+	if (me.multiSelect &&
+	    (me.displayField == me.valueField) &&
+	    me.store) {
+	    // warning, if this configuration is selected,
+	    // the following problem can occur:
+	    //
+	    // if the field is in an inputpanel/editwindow
+	    // there we maybe call resetOriginalValue before
+	    // our store is loaded and then we get a string
+	    // of form: "value1, value2, value3" instead of
+	    // an array
+	    //
+	    // this is because setValue of the combobox class
+	    // writes the joined array to rawvalue if displayfield
+	    // and valuefield are the same, and the store is
+	    // not yet loaded
+	    //
+	    // if we call getvalue after,
+	    // there is a test of getDisplayValue !== rawvalue
+	    // which fails (because displayvalue is "" in this case)
+	    // and sets the value to rawvalue,
+	    // which is now a string and not an array
+	    throw "warning: this configuration leads to errors";
+	}
+
+
 	me.mon(me.store, 'beforeload', function() {
 	    if (!me.isDisabled()) {
 		me.enableAfterLoad = true;
diff --git a/www/manager6/form/GroupSelector.js b/www/manager6/form/GroupSelector.js
index 8404d5f..9f2dd8f 100644
--- a/www/manager6/form/GroupSelector.js
+++ b/www/manager6/form/GroupSelector.js
@@ -5,7 +5,7 @@ Ext.define('PVE.form.GroupSelector', {
     allowBlank: false,
     autoSelect: false,
     valueField: 'groupid',
-    displayField: 'groupid',
+    displayField: 'groupname',
     listConfig: {
 	columns: [
 	    {
@@ -43,7 +43,14 @@ Ext.define('PVE.form.GroupSelector', {
 
     Ext.define('pve-groups', {
 	extend: 'Ext.data.Model',
-	fields: [ 'groupid', 'comment' ],
+	fields: [ 'groupid', 'comment',
+	    {
+		name: 'groupname',
+		calculate: function(data) {
+		    return data.groupid;
+		}
+	    }
+	],
 	proxy: {
             type: 'pve',
 	    url: "/api2/json/access/groups"
diff --git a/www/manager6/form/NodeSelector.js b/www/manager6/form/NodeSelector.js
index 8c69430..29c4437 100644
--- a/www/manager6/form/NodeSelector.js
+++ b/www/manager6/form/NodeSelector.js
@@ -14,9 +14,15 @@ Ext.define('PVE.form.NodeSelector', {
     // triggering dirtychange
     value: [],
     valueField: 'node',
-    displayField: 'node',
+    displayField: 'nodename',
     store: {
-	    fields: [ 'node', 'cpu', 'maxcpu', 'mem', 'maxmem', 'uptime' ],
+	    fields: [ 'node', 'cpu', 'maxcpu', 'mem', 'maxmem', 'uptime',
+		{
+		    name: 'nodename',
+		    calculate: function(data) {
+			return data.node;
+		}
+	    } ],
 	    proxy: {
 		type: 'pve',
 		url: '/api2/json/nodes'
-- 
2.1.4





More information about the pve-devel mailing list