[pve-devel] [PATCH widget-toolkit 2/2] ComboGrid: correctly set/mark multiSelect fields

Dominik Csapak d.csapak at proxmox.com
Mon Nov 25 11:04:57 CET 2019


in fields with 'multiSelect: true', we get an array as value instead
of a string, but a check of !![] results in true (since an array
is an object), so we have to explicitely check for arraylength
in 'setValue' (for correctly showing the trigger) and in the
load handler (to not set an empty field wrongfully to invalid)

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 form/ComboGrid.js | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/form/ComboGrid.js b/form/ComboGrid.js
index 3cc64f9..0c5cf1b 100644
--- a/form/ComboGrid.js
+++ b/form/ComboGrid.js
@@ -52,7 +52,8 @@ Ext.define('Proxmox.form.ComboGrid', {
 
     setValue: function(value) {
 	var me = this;
-	me.triggers.clear.setVisible(!!value && me.allowBlank);
+	let empty = Ext.isArray(value) ? !value.length : !value;
+	me.triggers.clear.setVisible(!empty && me.allowBlank);
 	return me.callParent([value]);
     },
 
@@ -458,7 +459,7 @@ Ext.define('Proxmox.form.ComboGrid', {
 		    if (me.autoSelect && rec && rec.data) {
 			def = rec.data[me.valueField];
 			me.setValue(def, true);
-		    } else {
+		    } else if (!me.allowBlank && ((Ext.isArray(def) && def.length) || def)) {
 			me.setValue(def);
 			if (!me.notFoundIsValid) {
 			    me.markInvalid(gettext('Invalid Value'));
-- 
2.20.1





More information about the pve-devel mailing list