diff options
| author | Aaron Bohy <aab@odoo.com> | 2019-04-11 13:35:49 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2019-04-23 06:58:16 +0000 |
| commit | 3c40d732bf03c8b656ab170319425f02fddfb2f4 (patch) | |
| tree | e59428c195f15fef590215f4da4f32f3665052ab | |
| parent | b130b35f048c6fbe9dd0ee1b076541e47b5788ad (diff) | |
[FIX] web: crash in editable lists with date field
Backport of 7bc53ac30e.
Assume an editable list view with a date(time) widget, click to
edit a line, focus the date field (the datepicker opens), press
ESC: there is a crash in the lib, and the datepicker remains open
forever.
This fix is twofold:
- we added a check in the lib to prevent it from crashing (it is
easily reproducible: it crashes when an opened datepicker is
removed from the DOM).
- we added an event handler of ESC keydown event to hide the
datepicker before the field is removed from the DOM.
closes odoo/odoo#32647
Signed-off-by: Martin Geubelle (mge) <mge@openerp.com>
| -rw-r--r-- | addons/web/static/lib/tempusdominus/tempusdominus.js | 3 | ||||
| -rw-r--r-- | addons/web/static/src/js/widgets/date_picker.js | 12 | ||||
| -rw-r--r-- | addons/web/static/tests/views/list_tests.js | 35 |
3 files changed, 48 insertions, 2 deletions
diff --git a/addons/web/static/lib/tempusdominus/tempusdominus.js b/addons/web/static/lib/tempusdominus/tempusdominus.js index ffca0c8e632..4eaf0df2a60 100644 --- a/addons/web/static/lib/tempusdominus/tempusdominus.js +++ b/addons/web/static/lib/tempusdominus/tempusdominus.js @@ -2754,7 +2754,8 @@ var TempusDominusBootstrap4 = function ($) { if ($target.length === 0) { return; } - if (config._options.debug || window.debug) { + // /!\ ODOO FIX: check on 'config' existence added by odoo + if (config && config._options.debug || window.debug) { return; } TempusDominusBootstrap4._jQueryInterface.call($target, 'hide', event); diff --git a/addons/web/static/src/js/widgets/date_picker.js b/addons/web/static/src/js/widgets/date_picker.js index 367ab23178d..57c935905e5 100644 --- a/addons/web/static/src/js/widgets/date_picker.js +++ b/addons/web/static/src/js/widgets/date_picker.js @@ -15,6 +15,7 @@ var DateWidget = Widget.extend({ 'change.datetimepicker': 'changeDatetime', 'change .o_datepicker_input': 'changeDatetime', 'input input': '_onInput', + 'keydown': '_onKeydown', 'show.datetimepicker': '_onDateTimePickerShow', }, /** @@ -240,6 +241,17 @@ var DateWidget = Widget.extend({ } }, /** + * @private + * @param {KeyEvent} ev + */ + _onKeydown: function (ev) { + if (ev.which === $.ui.keyCode.ESCAPE) { + this.__libInput++; + this.$el.datetimepicker('hide'); + this.__libInput--; + } + }, + /** * Prevents 'input' events triggered by the library to bubble up, as they * might have unwanted effects (like triggering 'field_changed' events in * the context of field widgets) diff --git a/addons/web/static/tests/views/list_tests.js b/addons/web/static/tests/views/list_tests.js index b422223d105..223aea85a93 100644 --- a/addons/web/static/tests/views/list_tests.js +++ b/addons/web/static/tests/views/list_tests.js @@ -278,7 +278,40 @@ QUnit.module('Views', { list.destroy(); }); - QUnit.test('editable list datetimepicker destroy widget', function (assert) { + QUnit.test('editable list datetimepicker destroy widget (edition)', function (assert) { + assert.expect(6); + var done = assert.async(); + + var list = createView({ + View: ListView, + model: 'foo', + data: this.data, + arch: '<tree editable="top">' + + '<field name="date"/>' + + '</tree>', + }); + list.$el.on({ + 'show.datetimepicker': function () { + assert.containsOnce(list, '.o_selected_row'); + assert.containsOnce($('body'), '.bootstrap-datetimepicker-widget'); + + list.$('input.o_datepicker_input').trigger($.Event('keydown', {which: $.ui.keyCode.ESCAPE})); + + assert.containsNone(list, '.o_selected_row'); + assert.containsNone($('body'), '.bootstrap-datetimepicker-widget'); + + done(); + list.destroy(); + } + }); + + assert.containsN(list, '.o_data_row', 4); + assert.containsNone(list, '.o_selected_row'); + + testUtilsDom.click(list.$('.o_data_cell:first')); + }); + + QUnit.test('editable list datetimepicker destroy widget (new line)', function (assert) { assert.expect(7); var done = assert.async(); |
