[FIX] web: prevent tab shortcut from crashing when no input field

Currently, using the shortcut "tab" inside a list will crash if the list has no input field (ex. if it has only a textarea field).

This commit prevents the bug.

Also moved the test for the orderedResIDs crash in the correct module.

PR #25209
This commit is contained in:
Sébastien Theys
2018-07-17 11:50:35 +02:00
parent 561d22feb7
commit d1f1cc9c27
2 changed files with 81 additions and 39 deletions
@@ -768,10 +768,13 @@ ListRenderer.include({
var record = this.state.data[this.currentRow];
var recordWidgets = this.allFieldWidgets[record.id];
var firstWidget = _.find(recordWidgets, function (widget) {
var isFirst = widget.$el.is(':visible') &&
(widget.$el.has('input').length > 0 ||
widget.tagName== 'input') &&
!widget.$el.hasClass('o_readonly_modifier');
var isFirst =
widget.$el.is(':visible') &&
(
widget.$('input').length > 0 || widget.tagName === 'input' ||
widget.$('textarea').length > 0 || widget.tagName === 'textarea'
) &&
!widget.$el.hasClass('o_readonly_modifier');
return isFirst;
});
return firstWidget;
@@ -9953,6 +9953,80 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('one2many add a line should not crash if orderedResIDs is not set', function (assert) {
// There is no assertion, the code will just crash before the bugfix.
assert.expect(0);
this.data.partner.records[0].turtles = [];
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form string="Partners">' +
'<header>' +
'<button name="action_invoice_open" type="object" string="Validate" class="oe_highlight"/>' +
'</header>' +
'<field name="turtles">' +
'<tree editable="bottom">' +
'<field name="turtle_foo"/>' +
'</tree>' +
'</field>' +
'</form>',
viewOptions: {
mode: 'edit',
},
intercepts: {
execute_action: function (event) {
event.data.on_fail();
},
},
});
$('button[name="action_invoice_open"]').click();
form.$('.o_field_x2many_list_row_add a').click();
form.destroy();
});
QUnit.test('one2many shortcut tab should not crash when there is no input widget', function (assert) {
assert.expect(2);
// create a one2many view which has no input (only 1 textarea in this case)
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form string="Partners">' +
'<field name="turtles">' +
'<tree editable="bottom">' +
'<field name="turtle_foo" widget="text"/>' +
'</tree>' +
'</field>' +
'</form>',
res_id: 1,
viewOptions: {
mode: 'edit',
},
});
// add a row, fill it, then trigger the tab shortcut
form.$('.o_field_x2many_list_row_add a').click();
form.$('.o_input[name="turtle_foo"]')
.val('ninja')
.trigger('input')
.trigger($.Event('keydown', {
which: $.ui.keyCode.TAB,
keyCode: $.ui.keyCode.TAB,
}));
assert.strictEqual(form.$('.o_field_text').text(), 'blipninja',
'current line should be saved');
assert.strictEqual(form.$('textarea.o_field_text').length, 1,
'new line should be created');
form.destroy();
});
QUnit.module('FieldMany2Many');
QUnit.test('many2many kanban: edition', function (assert) {
@@ -13017,41 +13091,6 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('add a line should not crash if orderedResIDs is not set', function (assert) {
// There is no assertion, the code will just crash before the bugfix.
assert.expect(0);
this.data.partner.records[0].turtles = [];
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch:'<form string="Partners">' +
'<header>' +
'<button name="action_invoice_open" type="object" string="Validate" class="oe_highlight"/>' +
'</header>' +
'<field name="turtles">' +
'<tree editable="bottom">' +
'<field name="turtle_foo"/>' +
'</tree>' +
'</field>' +
'</form>',
viewOptions: {
mode: 'edit',
},
intercepts: {
execute_action: function (event) {
event.data.on_fail();
},
},
});
$('button[name="action_invoice_open"]').click();
form.$('.o_field_x2many_list_row_add a').click();
form.destroy();
});
});
});
});