[FIX] web: focus select in reference widget

In the reference widget, the focus was always on the input (many2one) even
though the first select (with the model) was not set.

Thanks to @kaerdsar for the original PR.

Partially closes #24070
This commit is contained in:
Martin Geubelle
2018-04-17 15:31:32 +02:00
parent df02dc37fd
commit 9e6c616130
2 changed files with 41 additions and 0 deletions
@@ -2280,6 +2280,21 @@ var FieldReference = FieldMany2One.extend({
return this._super.apply(this, arguments);
},
//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------
/**
* @override
* @returns {jQuery}
*/
getFocusableElement: function () {
if (this.mode === 'edit' && !this.field.relation) {
return this.$('select');
}
return this._super.apply(this, arguments);
},
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
@@ -11298,6 +11298,32 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('reference and list navigation', function (assert) {
assert.expect(2);
var list = createView({
View: ListView,
model: 'partner',
data: this.data,
arch: '<tree editable="bottom"><field name="reference"/></tree>',
});
// edit first row
list.$('.o_data_row .o_data_cell').first().click();
assert.strictEqual(list.$('.o_data_row:eq(0) .o_field_widget[name="reference"] input')[0], document.activeElement,
'input of first data row should be selected');
// press TAB to go to next line
list.$('.o_data_row:eq(0) input').trigger($.Event('keydown', {
which: $.ui.keyCode.TAB,
keyCode: $.ui.keyCode.TAB,
}));
assert.strictEqual(list.$('.o_data_row:eq(1) .o_field_widget[name="reference"] select')[0], document.activeElement,
'select of second data row should be selected');
list.destroy();
});
QUnit.test('one2many with extra field from server not in form', function (assert) {
assert.expect(6);