From d1f1cc9c275de726de3cd2491c8d8b4866bbeb0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Theys?= Date: Tue, 10 Jul 2018 13:52:18 +0200 Subject: [PATCH] [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 --- .../js/views/list/list_editable_renderer.js | 11 +- .../tests/fields/relational_fields_tests.js | 109 ++++++++++++------ 2 files changed, 81 insertions(+), 39 deletions(-) diff --git a/addons/web/static/src/js/views/list/list_editable_renderer.js b/addons/web/static/src/js/views/list/list_editable_renderer.js index bf54ad19f22..382df0b9444 100644 --- a/addons/web/static/src/js/views/list/list_editable_renderer.js +++ b/addons/web/static/src/js/views/list/list_editable_renderer.js @@ -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; diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index b4b6e4cd6d2..54620fcf958 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -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:'
' + + '
' + + '
' + + '' + + '' + + '' + + '' + + '' + + '
', + 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:'
' + + '' + + '' + + '' + + '' + + '' + + '
', + 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:'
' + - '
' + - '
' + - '' + - '' + - '' + - '' + - '' + - '
', - 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(); - }); - }); }); });