all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH manager v3 03/18] ui: form: add filtered KVComboBox
Date: Mon,  2 Mar 2026 14:20:51 +0100	[thread overview]
Message-ID: <20260302132913.3169037-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20260302132913.3169037-1-d.csapak@proxmox.com>

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 <d.csapak@proxmox.com>
---
 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..035e80a8
--- /dev/null
+++ b/www/manager6/form/FilteredKVComboBox.js
@@ -0,0 +1,67 @@
+Ext.define('PVE.form.FilteredKVComboBox', {
+    extend: 'Proxmox.form.KVComboBox',
+    alias: ['widget.pveFilteredKVComboBox'],
+
+    // same as in the KVComboBox
+    comboItems: undefined,
+
+    // contains the allowed keys per category, e.g.
+    // {
+    //     category1: ['foo', 'bar'],
+    //     category2: ['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', me, isValid);
+        }
+    },
+
+    initComponent: function () {
+        var me = this;
+
+        me.callParent();
+
+        // initial filtering
+        me.setCategory(me.category);
+    },
+});
-- 
2.47.3





  parent reply	other threads:[~2026-03-02 13:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-02 13:20 [PATCH manager v3 00/18] enable qemu vm architecture selection Dominik Csapak
2026-03-02 13:20 ` [PATCH manager v3 01/18] api/pvestatd: broadcast and expose non-x86 host architecture Dominik Csapak
2026-03-02 13:20 ` [PATCH manager v3 02/18] ui: qemu: wizard: refactor ostype and cd selector into an OSPanel Dominik Csapak
2026-03-02 13:20 ` Dominik Csapak [this message]
2026-03-02 13:20 ` [PATCH manager v3 04/18] ui: resource store: add architecture field Dominik Csapak
2026-03-02 13:20 ` [PATCH manager v3 05/18] ui: qemu: add architecture specific defaults and helpers Dominik Csapak
2026-03-02 13:20 ` [PATCH manager v3 06/18] ui: qemu: add architecture field in wizard and hardware view Dominik Csapak
2026-03-02 13:20 ` [PATCH manager v3 07/18] ui: qemu: make scsi hw selector architecture aware Dominik Csapak
2026-03-02 13:20 ` [PATCH manager v3 08/18] ui: qemu: make osdefaults " Dominik Csapak
2026-03-02 13:20 ` [PATCH manager v3 09/18] ui: qemu: make os type selector " Dominik Csapak
2026-03-02 13:20 ` [PATCH manager v3 10/18] ui: qemu: make machine panels/fields " Dominik Csapak
2026-03-02 13:20 ` [PATCH manager v3 11/18] ui: qemu: make bios selector " Dominik Csapak
2026-03-02 13:21 ` [PATCH manager v3 12/18] ui: qemu: make sortByPreviousUsage " Dominik Csapak
2026-03-02 13:21 ` [PATCH manager v3 13/18] ui: qemu: wizard: use defaults to populate machine and bios Dominik Csapak
2026-03-02 13:21 ` [PATCH manager v3 14/18] ui: qemu: wizard: make iso confid architecture specific Dominik Csapak
2026-03-02 13:21 ` [PATCH manager v3 15/18] ui: qemu: make bus selector architecture aware Dominik Csapak
2026-03-02 13:21 ` [PATCH manager v3 16/18] ui: qemu: make processor edit " Dominik Csapak
2026-03-02 13:21 ` [PATCH manager v3 17/18] ui: qemu: change ui default for cpu model Dominik Csapak
2026-03-02 13:21 ` [PATCH manager v3 18/18] ui: qemu: set arch parameter for fetch machine types from api Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260302132913.3169037-4-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal