From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 11C50709AC for ; Mon, 7 Jun 2021 18:14:47 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id ECAE713D0C for ; Mon, 7 Jun 2021 18:14:16 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id CFD3B13CF4 for ; Mon, 7 Jun 2021 18:14:12 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 9629D4628F for ; Mon, 7 Jun 2021 18:14:12 +0200 (CEST) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Date: Mon, 7 Jun 2021 18:14:07 +0200 Message-Id: <20210607161407.4157537-1-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.963 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] applied: [PATCH] combo grid: load: rework auto-selection and validity logic X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jun 2021 16:14:47 -0000 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 --- 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