]> git.proxmox.com Git - proxmox-widget-toolkit.git/blobdiff - form/ComboGrid.js
fix #2421: ComboGrid: correctly validate multiSelect variant
[proxmox-widget-toolkit.git] / form / ComboGrid.js
index 608f6138f7e222dae6e9c1ad4da6ea812bf192fe..3cc64f92c8b1748b54a78e951335614bfd7c9b8f 100644 (file)
@@ -38,6 +38,24 @@ Ext.define('Proxmox.form.ComboGrid', {
 
     editable: false,
 
+    triggers: {
+       clear: {
+           cls: 'pmx-clear-trigger',
+           weight: -1,
+           hidden: true,
+           handler: function() {
+               var me = this;
+               me.setValue('');
+           }
+       }
+    },
+
+    setValue: function(value) {
+       var me = this;
+       me.triggers.clear.setVisible(!!value && me.allowBlank);
+       return me.callParent([value]);
+    },
+
     // override ExtJS method
     // if the field has multiSelect enabled, the store is not loaded, and
     // the displayfield == valuefield, it saves the rawvalue as an array
@@ -292,6 +310,18 @@ Ext.define('Proxmox.form.ComboGrid', {
         return picker;
     },
 
+    clearLocalFilter: function() {
+        var me = this,
+            filter = me.queryFilter;
+
+        if (filter) {
+            me.queryFilter = null;
+            me.changingFilters = true;
+            me.store.removeFilter(filter, true);
+            me.changingFilters = false;
+        }
+    },
+
     isValueInStore: function(value) {
        var me = this;
        var store = me.store;
@@ -301,6 +331,13 @@ Ext.define('Proxmox.form.ComboGrid', {
            return found;
        }
 
+       // Make sure the current filter is removed before checking the store
+       // to prevent false negative results when iterating over a filtered store.
+       // All store.find*() method's operate on the filtered store.
+       if (me.queryFilter && me.queryMode === 'local' && me.clearFilterOnBlur) {
+           me.clearLocalFilter();
+       }
+
        if (Ext.isArray(value)) {
            Ext.Array.each(value, function(v) {
                if (store.findRecord(me.valueField, v)) {
@@ -322,6 +359,17 @@ Ext.define('Proxmox.form.ComboGrid', {
            return true; // handled later by allowEmpty in the getErrors call chain
        }
 
+       // we normally get here the displayField as value, but if a valueField
+       // is configured we need to get the "actual" value, to ensure it is in
+       // the store. Below check is copied from ExtJS 6.0.2 ComboBox source
+       //
+       // we also have to get the 'real' value if the we have a mulitSelect
+       // Field but got a non array value
+       if ((me.valueField && me.valueField !== me.displayField) ||
+           (me.multiSelect && !Ext.isArray(value))) {
+           value = me.getValue();
+       }
+
        if (!(me.notFoundIsValid || me.isValueInStore(value))) {
            return gettext('Invalid Value');
        }