[FIX] web: no M2ODialog when pressing enter in a many2one

Before this revision, pressing ENTER when inside a many2one field
triggers a 'focus out' event. In particular, if one creates a many2one
record and uses the ENTER key to click "Create and Edit", two dialog
windows appear: one to actually create the associated record, and a
second to alert the user that they are creating an associated record.
The latter appears every time the many2one field loses focus.

This commit changes the 'key up' event for many2one fields to ensure
that the ENTER key does not trigger a 'focus out' event.
This commit is contained in:
Khoi Nguyen
2017-07-14 10:35:35 +02:00
parent a562f5ced1
commit f2c7e44efe
2 changed files with 55 additions and 1 deletions
@@ -485,8 +485,16 @@ var FieldMany2One = AbstractField.extend({
},
/**
* @private
*
* @param {OdooEvent} ev
*/
_onInputKeyup: function () {
_onInputKeyup: function (ev) {
if (ev.which === $.ui.keyCode.ENTER) {
// If we pressed enter, we want to prevent _onInputFocusout from
// executing since it would open a M2O dialog to request
// confirmation that the many2one is not properly set.
return;
}
if (this.$input.val() === "") {
this.reinitialize(false);
} else if (this._getDisplayName(this.m2o_value) !== this.$input.val()) {
@@ -1141,6 +1141,52 @@ QUnit.module('relational_fields', {
});
});
QUnit.test('pressing ENTER on a \'no_quick_create\' many2one should not trigger M2ODialog', function (assert) {
var done = assert.async();
assert.expect(1);
var M2O_DELAY = relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY;
relationalFields.FieldMany2One.prototype.AUTOCOMPLETE_DELAY = 0;
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form>' +
'<field name="trululu" options="{\'no_quick_create\': True}"/>' +
'<field name="foo"/>' +
'</form>',
archs: {
'partner,false,form': '<form string="Partners"><field name="display_name"/></form>',
},
});
var $input = form.$('.o_field_many2one input');
$input.val("Something that does not exist").trigger('input');
$('.ui-autocomplete .ui-menu-item a:contains(Create and)').trigger('mouseenter');
concurrency.delay(0).then(function() {
$input.trigger($.Event('keydown', {
which: $.ui.keyCode.ENTER,
keyCode: $.ui.keyCode.ENTER,
}));
$input.trigger($.Event('keypress', {
which: $.ui.keyCode.ENTER,
keyCode: $.ui.keyCode.ENTER,
}));
$input.trigger($.Event('keyup', {
which: $.ui.keyCode.ENTER,
keyCode: $.ui.keyCode.ENTER,
}));
concurrency.delay(0).then(function() {
$input.blur();
assert.strictEqual($('.modal').length, 1,
"should have one modal in body");
form.destroy();
done();
});
});
});
QUnit.test('many2one in editable list + onchange, with enter [REQUIRE FOCUS]', function (assert) {
assert.expect(6);
var done = assert.async();