[FIX]web: do not crash when dismissing a modal with escape

stopPropagation of navigation_move event for where direction=cancel,
currently if navigation_move event throws error when user press escape
in dialog where dialog is opened from editable list record

Scenario: Install website_sale -> Open Product form(variant enable) ->
open variant tab -> open Attribute m2o form popup and press Escape on dialog
Result: Error
Expected: It should close dialog and keep editable list view record open,
btw m2o field should also be focused when dialog is closed but that's
another issue, will be fixed in another ongoing task

Related to Issue: #1873919

Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
Co-authored-by: Mohammed Shekha <msh@odoo.com>
This commit is contained in:
Mohammed Shekha
2018-10-09 09:46:39 +02:00
committed by Vincent Schippefilt
co-authored by Vincent Schippefilt Mohammed Shekha
parent fc411ceb19
commit 8445baa08d
2 changed files with 54 additions and 4 deletions
@@ -950,10 +950,7 @@ var FormRenderer = BasicRenderer.extend({
* @param {OdooEvent} ev
*/
_onNavigationMove: function (ev) {
if (ev.data.direction !== "cancel") {
ev.stopPropagation();
}
ev.stopPropagation();
var index;
if (ev.data.direction === "next") {
index = this.allFieldWidgets[this.state.id].indexOf(ev.data.target || ev.target);
@@ -12758,6 +12758,59 @@ QUnit.module('relational_fields', {
form.destroy();
});
QUnit.test('when creating a new many2one on a x2many then discarding it immediately with ESCAPE, it should not crash', function (assert) {
var done = assert.async();
assert.expect(1);
this.data.partner.records[0].turtles = [];
var form = createView({
View: FormView,
model: 'partner',
viewOptions: {
mode: 'edit',
},
data: this.data,
arch:'<form string="Partners">' +
'<sheet>' +
'<field name="turtles">' +
'<tree editable="top">' +
'<field name="turtle_foo"/>' +
'<field name="turtle_trululu"/>' +
'</tree>' +
'</field>' +
'</sheet>' +
'</form>',
res_id: 1,
archs: {
'partner,false,form': '<form><group><field name="foo"/><field name="bar"/></group></form>'
},
});
// add a new line
form.$el.find('.o_field_x2many_list_row_add>a').click();
// open the field turtle_trululu (one2many)
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
form.$el.find('.o_input_dropdown>input').click();
concurrency.delay(0).then(function () {
// click create and edit
$('.ui-autocomplete .ui-menu-item a:contains(Create and)').trigger('mouseenter').click();
// hit escape immediately
var escapeKey = $.ui.keyCode.ESCAPE;
$(document.activeElement).trigger(
$.Event('keydown', {which: escapeKey, keyCode: escapeKey}));
assert.ok('did not crash');
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = M2O_DELAY;
form.destroy();
done();
});
});
});
});
});