Skip to content

Commit

Permalink
[FIX] web: crash in editable lists with date field
Browse files Browse the repository at this point in the history
Backport of 7bc53ac.

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 #32647

Signed-off-by: Martin Geubelle (mge) <mge@openerp.com>
  • Loading branch information
aab-odoo committed Apr 23, 2019
1 parent b130b35 commit 3c40d73
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
3 changes: 2 additions & 1 deletion addons/web/static/lib/tempusdominus/tempusdominus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions addons/web/static/src/js/widgets/date_picker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var DateWidget = Widget.extend({
'change.datetimepicker': 'changeDatetime',
'change .o_datepicker_input': 'changeDatetime',
'input input': '_onInput',
'keydown': '_onKeydown',
'show.datetimepicker': '_onDateTimePickerShow',
},
/**
Expand Down Expand Up @@ -239,6 +240,17 @@ var DateWidget = Widget.extend({
this.$input.select();
}
},
/**
* @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
Expand Down
35 changes: 34 additions & 1 deletion addons/web/static/tests/views/list_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 3c40d73

Please sign in to comment.