]> git.proxmox.com Git - proxmox-widget-toolkit.git/commitdiff
combogrid: add handling for historic set values currently not available
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 18 Jul 2019 13:55:37 +0000 (15:55 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 18 Jul 2019 13:55:38 +0000 (15:55 +0200)
We can often run into situations where a value set in the past is not
valid anymore. An example could be a deleted network bridge, e.g., we
set the vNIC of a VM to 'vmbr1' but then we decide to obsolete that
and delete that one, one would now expect that the field gets marked
as invalid when editing the VM's vNIC, so add that behavior.

As sometimes this can be valid and wanted behavior (e.g., usb
passthrough, which is hot-pluggable), also add a switch do restore
the old behavior.

Note that the empty value is not handled by this change, we let the
existing "allowBlank" config switch handle that one.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
form/ComboGrid.js

index a0c762cf05316bddc1b4673330e749e273f83936..608f6138f7e222dae6e9c1ad4da6ea812bf192fe 100644 (file)
@@ -29,6 +29,7 @@ Ext.define('Proxmox.form.ComboGrid', {
 
     config: {
        skipEmptyText: false,
+       notFoundIsValid: false,
        deleteEmpty: false,
     },
 
@@ -291,6 +292,43 @@ Ext.define('Proxmox.form.ComboGrid', {
         return picker;
     },
 
+    isValueInStore: function(value) {
+       var me = this;
+       var store = me.store;
+       var found = false;
+
+       if (!store) {
+           return found;
+       }
+
+       if (Ext.isArray(value)) {
+           Ext.Array.each(value, function(v) {
+               if (store.findRecord(me.valueField, v)) {
+                   found = true;
+                   return false; // break
+               }
+           });
+       } else {
+           found = !!store.findRecord(me.valueField, value);
+       }
+
+       return found;
+    },
+
+    validator: function (value) {
+       var me = this;
+
+       if (!value) {
+           return true; // handled later by allowEmpty in the getErrors call chain
+       }
+
+       if (!(me.notFoundIsValid || me.isValueInStore(value))) {
+           return gettext('Invalid Value');
+       }
+
+       return true;
+    },
+
     initComponent: function() {
        var me = this;
 
@@ -364,16 +402,7 @@ Ext.define('Proxmox.form.ComboGrid', {
                }
                var found = false;
                if (def) {
-                   if (Ext.isArray(def)) {
-                       Ext.Array.each(def, function(v) {
-                           if (store.findRecord(me.valueField, v)) {
-                               found = true;
-                               return false; // break
-                           }
-                       });
-                   } else {
-                       found = store.findRecord(me.valueField, def);
-                   }
+                   found = me.isValueInStore(def);
                }
 
                if (!found) {
@@ -383,6 +412,9 @@ Ext.define('Proxmox.form.ComboGrid', {
                        me.setValue(def, true);
                    } else {
                        me.setValue(def);
+                       if (!me.notFoundIsValid) {
+                           me.markInvalid(gettext('Invalid Value'));
+                       }
                    }
                }
            }