]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
combo grid: load: rework auto-selection and validity logic
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 7 Jun 2021 16:03:25 +0000 (18:03 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 7 Jun 2021 16:10:15 +0000 (18:10 +0200)
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@proxmox.com>
src/form/ComboGrid.js

index af04559308ce19e9bdad057aa55741a34b08ca6d..923a55a7ea9c4dd95a9d58f1022066c44dfff13d 100644 (file)
@@ -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 {