[pve-devel] applied: [PATCH] combo grid: load: rework auto-selection and validity logic

Thomas Lamprecht t.lamprecht at proxmox.com
Mon Jun 7 18:14:07 CEST 2021


We do not want to trigger an autoSelect if there's a value set, even
if it isn't found in the store, as that hides the fact that an (now)
invalid valid is configured from the user, which can be confusing if
something is not working, as when editing an object it seems like a
valid value is selected.

Further, if a value is set we mark the field as invalid from the
start, at least if it's neither disabled nor allowed to have a
value which is does not exists in the backing store.

Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---

As it's a change in a rather tricky place for something where we had a
few "fixes" already it's something which gave me a slight headache, but
IMO the shift in semantics makes it more friendly to use as developer,
and makes autoSelect behave more like one would expect, i.e., autoSelect
if nothing is selected (avoiding a `me.autoSelect = me.isCreate` logic)

 src/form/ComboGrid.js | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/form/ComboGrid.js b/src/form/ComboGrid.js
index af04559..923a55a 100644
--- a/src/form/ComboGrid.js
+++ b/src/form/ComboGrid.js
@@ -445,15 +445,19 @@ Ext.define('Proxmox.form.ComboGrid', {
 		}
 
 		if (!found) {
-		    let rec = me.store.first();
-		    if (me.autoSelect && rec && rec.data) {
-			def = rec.data[me.valueField];
-			me.setValue(def, true);
-		    } else if (!me.allowBlank && !(Ext.isArray(def) ? def.length : def)) {
-			me.setValue(def);
-			if (!me.notFoundIsValid && !me.isDisabled()) {
-			    me.markInvalid(me.blankText);
+		    if (!(Ext.isArray(def) ? def.length : def)) {
+			let rec = me.store.first();
+			if (me.autoSelect && rec && rec.data) {
+			    def = rec.data[me.valueField];
+			    me.setValue(def, true);
+			} else if (!me.allowBlank) {
+			    me.setValue(def);
+			    if (!me.isDisabled()) {
+				me.markInvalid(me.blankText);
+			    }
 			}
+		    } else if (!me.notFoundIsValid && !me.isDisabled()) {
+			me.markInvalid(gettext('Invalid Value'));
 		    }
 		}
 	    } else {
-- 
2.30.2






More information about the pve-devel mailing list