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(); - }); - }); }); });