From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id C5BCD1FF137 for ; Tue, 03 Feb 2026 11:21:26 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id DFD9518F1E; Tue, 3 Feb 2026 11:21:54 +0100 (CET) From: Dominik Csapak To: pve-devel@lists.proxmox.com Subject: [PATCH manager v2 03/17] ui: form: add filtered KVComboBox Date: Tue, 3 Feb 2026 11:00:08 +0100 Message-ID: <20260203102118.1430545-4-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260203102118.1430545-1-d.csapak@proxmox.com> References: <20260203102118.1430545-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.032 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy 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 Message-ID-Hash: 7GUTAJBYMTQ5VKP5PS3DIC4VDCDOVPBR X-Message-ID-Hash: 7GUTAJBYMTQ5VKP5PS3DIC4VDCDOVPBR X-MailFrom: d.csapak@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: this makes it easier to have the same KVComboBox, but for different configurations, depending on a single 'category' value. This is useful for having the same KVComboBox in different categories, such as the cpu architecture, for e.g. the scsi hw or bios selector, which need different values for different architectures. Instead of implementing the logic for each KVComboBox, abstract it away, so we can reuse the code and have consistent behavior here. Signed-off-by: Dominik Csapak --- www/manager6/Makefile | 1 + www/manager6/form/FilteredKVComboBox.js | 67 +++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 www/manager6/form/FilteredKVComboBox.js diff --git a/www/manager6/Makefile b/www/manager6/Makefile index 944dd873..8857045c 100644 --- a/www/manager6/Makefile +++ b/www/manager6/Makefile @@ -17,6 +17,7 @@ JSSRC= \ data/ResourceStore.js \ data/model/RRDModels.js \ container/TwoColumnContainer.js \ + form/FilteredKVComboBox.js \ form/ACMEAPISelector.js \ form/ACMEAccountSelector.js \ form/ACMEPluginSelector.js \ diff --git a/www/manager6/form/FilteredKVComboBox.js b/www/manager6/form/FilteredKVComboBox.js new file mode 100644 index 00000000..0e24a79f --- /dev/null +++ b/www/manager6/form/FilteredKVComboBox.js @@ -0,0 +1,67 @@ +Ext.define('PVE.form.FilteredKVComboBox', { + extend: 'Proxmox.form.KVComboBox', + alias: ['widget.pveFilteredKVComboBox'], + + // sam as in the KVComboBox + comboItems: undefined, + + // contains the allowed keys per category, e.g. + // { + // category1: ['foo', 'bar'], + // cateogry2: ['foo'],' + // } + // + // to have an effect, the listed values must exist in the comboItems list + allowedValuesPerCategory: {}, + + // the current category. If not set, the store is not filtered. + category: undefined, + + // If set, will be used to update the display value of the '__default__' value + // that is usually set in a KVComboBox. + // + // gets the current category (if any) as parameter) + setDefaultDisplay: undefined, + + setCategory: function (category) { + let me = this; + me.category = category; + me.filterByCategory(category); + }, + + filterByCategory: function (category) { + let me = this; + let wasValid = me.isValid(); + me.store.clearFilter(); + + let allowedKeys = me.allowedValuesPerCategory[category]; + if (allowedKeys) { + me.store.addFilter((rec) => allowedKeys.indexOf(rec.data.key) !== -1); + } + + let isValid = me.isValid(); + // update default value with new arch + if (Ext.isFunction(me.setDefaultDisplay)) { + let record = me.store.findRecord('key', '__default__'); + if (record) { + record.set('value', me.setDefaultDisplay(category)); + record.commit(); + } + } + + // for some reason, adding/changing filters does not trigger this, even though + // it show the field as invalid, so simply track and fire the event manually. + if (wasValid !== isValid) { + me.fireEvent('validitychange', isValid); + } + }, + + initComponent: function () { + var me = this; + + me.callParent(); + + // initial filtering + me.setCategory(me.category); + }, +}); -- 2.47.3