combo grid: load: rework auto-selection and validity logic

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>
This commit is contained in:
Thomas Lamprecht 2021-06-07 18:03:25 +02:00
parent a0451be0ca
commit 585f3c31e7

View 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 {