[FIX] web: enter edition editable list with <widget>

Let's assume an editable list view with a <widget> node in its
arch. Before this rev., when clicking on a field cell positionned
*after* the widget, the field next to the clicked one was focused.

closes odoo/odoo#36176

Signed-off-by: Géry Debongnie (ged) <ged@openerp.com>
This commit is contained in:
Aaron Bohy
2019-08-28 11:24:48 +00:00
parent 52c6a060d6
commit 711a10162a
3 changed files with 31 additions and 1 deletions
@@ -1268,7 +1268,7 @@ ListRenderer.include({
var $td = $(event.currentTarget);
var $tr = $td.parent();
var rowIndex = $tr.prop('rowIndex') - 1;
var fieldIndex = Math.max($tr.find('.o_data_cell').not('.o_list_button').index($td), 0);
var fieldIndex = Math.max($tr.find('.o_field_cell').index($td), 0);
this._selectCell(rowIndex, fieldIndex, {event: event});
},
/**
@@ -385,6 +385,7 @@ var ListRenderer = BasicRenderer.extend({
if (node.tag === 'button') {
tdClassName += ' o_list_button';
} else if (node.tag === 'field') {
tdClassName += ' o_field_cell';
var typeClass = FIELD_CLASSES[this.state.fields[node.attrs.name].type];
if (typeClass) {
tdClassName += (' ' + typeClass);
@@ -7028,6 +7028,35 @@ QUnit.module('Views', {
list.destroy();
});
QUnit.test('enter edition in editable list with <widget>', async function (assert) {
assert.expect(1);
var MyWidget = Widget.extend({
start: function () {
this.$el.html('<i class="fa fa-info"/>');
},
});
widgetRegistry.add('some_widget', MyWidget);
var list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree editable="top">' +
'<widget name="some_widget"/>' +
'<field name="int_field"/>' +
'<field name="qux"/>' +
'</tree>',
});
// click on int_field cell of first row
await testUtils.dom.click(list.$('.o_data_row:first .o_data_cell:nth(1)'));
assert.strictEqual(document.activeElement.name, "int_field");
list.destroy();
delete widgetRegistry.map.test;
});
});
});