Skip to content
Permalink
Browse files

[FIX] web: list many2one quick-create

Allows the quick create on m2o in list views

Before this commit, when entering a new value in a many2one in a list and
exiting the cell through a click, the quick-create modal appeared for the
duration of the mousedown.

Now, the modal remains and allow to edit the new many2one value

Task 2076380

closes #37721

Signed-off-by: VincentSchippefilt <VincentSchippefilt@users.noreply.github.com>
  • Loading branch information...
Arcasias committed Oct 1, 2019
1 parent 09bbc03 commit c6f1f054662574d16d9673218b5172f02a1636a3
Showing with 59 additions and 0 deletions.
  1. +30 −0 addons/web/static/src/js/fields/relational_fields.js
  2. +29 −0 addons/web/static/tests/views/list_tests.js
@@ -652,6 +652,36 @@ var ListFieldMany2One = FieldMany2One.extend({
_renderReadonly: function () {
this.$el.text(this.m2o_value);
},

//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------

/**
* In case the focus is lost from a mousedown, we want to prevent the click occuring on the
* following mouseup since it might trigger some unwanted list functions.
* If it's not the case, we want to remove the added handler on the next mousedown.
* @see list_editable_renderer._onWindowClicked()
*
* @override
* @private
*/
_onInputFocusout: function () {
if (this.can_create && this.floating) {
// In case the focus out is due to a mousedown, we want to prevent the next click
var attachedEvents = ['click', 'mousedown'];
var stopNextClick = (function (ev) {
ev.stopPropagation();
attachedEvents.forEach(function (eventName) {
window.removeEventListener(eventName, stopNextClick, true);
});
}).bind(this);
attachedEvents.forEach(function (eventName) {
window.addEventListener(eventName, stopNextClick, true);
});
}
return this._super.apply(this, arguments);
},
});

var KanbanFieldMany2One = AbstractField.extend({
@@ -3846,6 +3846,35 @@ QUnit.module('Views', {

list.destroy();
});

QUnit.test("quickcreate in a many2one in a list", function (assert) {
assert.expect(2);

var list = createView({
arch: '<tree editable="top"><field name="m2o"/></tree>',
data: this.data,
model: 'foo',
View: ListView,
});

list.$('.o_data_row:first .o_data_cell:first').click();

var $input = list.$('.o_data_row:first .o_data_cell:first input');
$input.val("aaa");
$input.trigger('keyup');
$input.trigger('blur');
list.el.click();

assert.strictEqual(document.body.getElementsByClassName('modal').length, 1,
"the quick_create modal should appear");

$('.modal .btn-primary:first').click();
list.el.click();

assert.strictEqual(list.$('.o_data_row:first').text(), "aaa", "value should have been updated");

list.destroy();
});
});

});

0 comments on commit c6f1f05

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