Skip to content
Permalink
Browse files

[FIX] web: crash in editable lists with date field

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 11, 2019
1 parent b130b35 commit 3c40d732bf03c8b656ab170319425f02fddfb2f4
@@ -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);
@@ -15,6 +15,7 @@ var DateWidget = Widget.extend({
'change.datetimepicker': 'changeDatetime',
'change .o_datepicker_input': 'changeDatetime',
'input input': '_onInput',
'keydown': '_onKeydown',
'show.datetimepicker': '_onDateTimePickerShow',
},
/**
@@ -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
@@ -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();

0 comments on commit 3c40d73

Please sign in to comment.
You can’t perform that action at this time.