open picker for all comboboxes on focus, even if they are editable

when a combobox was editable, a click inside did not open the picker,
but it would if the combobox was not editable.

Since this is
 1. Inconsistent
 2. Inconvenient (the user has to specifically press the arrow)

we already had this implemented for our ComboGrid, but not for
regular comboboxes

This patch moves the code for this to an override for ComboBox, which
our ComboGrid then inherits (so we do not need it there anymore)

while at it, do some non-significant code-cleanup
 * whitespace fixes
 * don't shadow 'me' in the focus callback
 * fix typo in comment

Originally this was implemented in pve-manager, commit
851c032d69ad5ae23725dd1add9e4084ebc12650

https://git.proxmox.com/?p=pve-manager.git;a=commitdiff;h=851c032d69ad5ae23725dd1add9e4084ebc12650

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Originally-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-04-16 13:13:46 +02:00 committed by Thomas Lamprecht
parent e1b9384897
commit 5003213241
2 changed files with 30 additions and 24 deletions

View File

@ -333,7 +333,36 @@ Ext.define('Proxmox.form.ComboBox', {
me.clearValue();
me.setValue(me.originalValue);
}
}
},
// we also want to open the trigger on editable comboboxes by default
initComponent: function() {
let me = this;
me.callParent();
if (me.editable) {
// The trigger.picker causes first a focus event on the field then
// toggles the selection picker. Thus skip expanding in this case,
// else our focus listener expands and the picker.trigger then
// collapses it directly afterwards.
Ext.override(me.triggers.picker, {
onMouseDown: function(e) {
// copied "should we focus" check from Ext.form.trigger.Trigger
if (e.pointerType !== 'touch' && !this.field.owns(Ext.Element.getActiveElement())) {
me.skip_expand_on_focus = true;
}
this.callParent(arguments);
}
});
me.on("focus", function(combobox) {
if (!combobox.isExpanded && !combobox.skip_expand_on_focus) {
combobox.expand();
}
combobox.skip_expand_on_focus = false;
});
}
},
});
// when refreshing a grid/tree view, restoring the focus moves the view back to

View File

@ -404,29 +404,6 @@ Ext.define('Proxmox.form.ComboGrid', {
me.createPicker();
}
if (me.editable) {
// The trigger.picker causes first a focus event on the field then
// toggles the selection picker. Thus skip expanding in this case,
// else our focus listner expands and the picker.trigger then
// collapses it directly afterwards.
Ext.override(me.triggers.picker, {
onMouseDown : function (e) {
// copied "should we focus" check from Ext.form.trigger.Trigger
if (e.pointerType !== 'touch' && !this.field.owns(Ext.Element.getActiveElement())) {
me.skip_expand_on_focus = true;
}
this.callParent(arguments);
}
});
me.on("focus", function(me) {
if (!me.isExpanded && !me.skip_expand_on_focus) {
me.expand();
}
me.skip_expand_on_focus = false;
});
}
me.mon(me.store, 'beforeload', function() {
if (!me.isDisabled()) {
me.enableLoadMask = true;