[FIX] web: fixed crash in editable grouped lists

Adding a line in grouped listviews caused a crash in some cases.

Steps to reproduce:
- go in any grouped editable list view
- click on any "Add a line" cell, but not on the link itself
- press ENTER

Before this commit:
A crash occured. Unable to add a new line. Needed to refresh the page.

After this commit:
Line addition functionnality properly working even when selecting the outer cell
This commit is contained in:
Julien Mougenot
2019-08-16 09:03:49 +00:00
parent 4817c7f08f
commit 291dad6bc8
2 changed files with 27 additions and 2 deletions
@@ -1035,7 +1035,10 @@ ListRenderer.include({
ev.stopPropagation();
var self = this;
var groupId = $(ev.target).data('group-id');
// This method can be called when selecting the parent of the link.
// We need to ensure that the link is the actual target
const target = ev.target.tagName !== 'A' ? ev.target.getElementsByTagName('A')[0] : ev.target;
const groupId = target.dataset.groupId;
this.currentGroupId = groupId;
this.unselectRow().then(function () {
self.trigger_up('add_record', {
@@ -1195,7 +1198,7 @@ ListRenderer.include({
var correspondingRow = self._getRow(recordId);
correspondingRow.children().eq(cellIndex).focus();
} else if (self.currentGroupId) {
self.$('a[data-group-id=' + self.currentGroupId + ']').focus();
self.$('a[data-group-id="' + self.currentGroupId + '"]').focus();
} else {
self.$('.o_field_x2many_list_row_add a:first').focus(); // FIXME
}
@@ -6273,6 +6273,28 @@ QUnit.module('Views', {
list.destroy();
});
QUnit.test('add and discard a line through keyboard navigation without crashing', async function (assert) {
assert.expect(2);
var list = await createView({
View: ListView,
model: 'foo',
data: this.data,
arch: '<tree editable="bottom"><field name="foo" required="1"/></tree>',
groupBy: ['bar'],
});
await testUtils.dom.click(list.$('.o_group_header:first')); // open group
// Triggers ENTER on "Add a line" wrapper cell
await testUtils.fields.triggerKeydown(list.$('.o_group_field_row_add'), 'enter');
assert.containsN(list, 'tbody:nth(1) .o_data_row', 4, "new data row should be created");
await testUtils.dom.click(list.$buttons.find('.o_list_button_discard'));
// At this point, a crash manager should appear if no proper link targetting
assert.containsN(list, 'tbody:nth(1) .o_data_row', 3,"new data row should be discarded.");
list.destroy();
});
QUnit.test('editable grouped list with create="0"', async function (assert) {
assert.expect(1);