From 2d3e5711f1229c4be52e3f8553feb734fc3d1a44 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 26 Sep 2017 13:55:13 +0200 Subject: [PATCH] [FIX] web: escape pressed in editable list in dialog should discard the edited row, but not close the dialog. Before this rev., it was closing the dialog. --- .../static/src/js/fields/abstract_field.js | 2 +- .../js/views/list/list_editable_renderer.js | 3 ++ .../tests/fields/relational_fields_tests.js | 49 ++++++++++++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/fields/abstract_field.js b/addons/web/static/src/js/fields/abstract_field.js index 9b484354544..25aa9fceda9 100644 --- a/addons/web/static/src/js/fields/abstract_field.js +++ b/addons/web/static/src/js/fields/abstract_field.js @@ -444,7 +444,7 @@ var AbstractField = Widget.extend({ this.trigger_up('navigation_move', {direction: 'next_line'}); break; case $.ui.keyCode.ESCAPE: - this.trigger_up('navigation_move', {direction: 'cancel'}); + this.trigger_up('navigation_move', {direction: 'cancel', originalEvent: ev}); break; case $.ui.keyCode.UP: ev.stopPropagation(); 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 6519fdfaec4..1a2fe3bd624 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 @@ -661,6 +661,9 @@ ListRenderer.include({ this._moveToNextLine(); break; case 'cancel': + // stop the original event (typically an ESCAPE keydown), to + // prevent from closing the potential dialog containing this list + ev.data.originalEvent.stopPropagation(); this.trigger_up('discard_changes', { recordID: ev.target.dataPointID, }); diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js index 75ee8e8bf3e..ab19f58a344 100644 --- a/addons/web/static/tests/fields/relational_fields_tests.js +++ b/addons/web/static/tests/fields/relational_fields_tests.js @@ -3204,6 +3204,54 @@ QUnit.module('relational_fields', { form.destroy(); }); + QUnit.test('pressing escape in editable o2m list in dialog', function (assert) { + assert.expect(3); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '' + + '
', + res_id: 1, + archs: { + "partner,false,form": '
' + + '' + + '' + + '' + + '' + + '' + + '
', + }, + viewOptions: { + mode: 'edit', + }, + }); + + form.$('.o_field_x2many_list_row_add a').click(); + $('.modal .o_field_x2many_list_row_add a').click(); + + assert.strictEqual($('.modal .o_data_row.o_selected_row').length, 1, + "there should be a row in edition in the dialog"); + + // trigger keydown ESCAPE in the edited row + $('.modal .o_data_cell input').trigger({type: 'keydown', which: $.ui.keyCode.ESCAPE}); + + assert.strictEqual($('.modal').length, 1, + "dialog should still be open"); + assert.strictEqual($('.modal .o_data_row').length, 0, + "the row should have been removed"); + + form.destroy(); + }); + QUnit.test('editable o2m with onchange and required field: delete an invalid line', function (assert) { assert.expect(5); @@ -5586,7 +5634,6 @@ QUnit.module('relational_fields', { form.destroy(); }); - QUnit.test('editing tabbed one2many (editable=bottom)', function (assert) { assert.expect(11);