Skip to content

Commit

Permalink
[FIX] web: list many2one quick-create
Browse files Browse the repository at this point in the history
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

X-original-commit: c00f84e
  • Loading branch information
fw-bot committed Oct 9, 2019
1 parent badd0c0 commit 5817f0e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
20 changes: 19 additions & 1 deletion addons/web/static/src/js/fields/relational_fields.js
Expand Up @@ -901,14 +901,32 @@ var ListFieldMany2One = FieldMany2One.extend({
this.m2oDialogFocused = false; this.m2oDialogFocused = false;
}, },
/** /**
* In list views, we don't want to try to trigger a fieldChange when the field * 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()
*
* Also, in list views, we don't want to try to trigger a fieldChange when the field
* is being emptied. Instead, it will be triggered as the user leaves the field * is being emptied. Instead, it will be triggered as the user leaves the field
* while it is empty. * while it is empty.
* *
* @override * @override
* @private * @private
*/ */
_onInputFocusout: function () { _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);
});
}
this._super.apply(this, arguments); this._super.apply(this, arguments);
if (!this.m2oDialogFocused && this.$input.val() === "" && this.mustSetValue) { if (!this.m2oDialogFocused && this.$input.val() === "" && this.mustSetValue) {
this.reinitialize(false); this.reinitialize(false);
Expand Down
30 changes: 30 additions & 0 deletions addons/web/static/tests/views/list_tests.js
Expand Up @@ -8258,6 +8258,36 @@ QUnit.module('Views', {


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

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

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

const $input = list.$('.o_data_row:first .o_data_cell:first input');
await testUtils.fields.editInput($input, "aaa");
$input.trigger('keyup');
$input.trigger('blur');
document.body.click();

await testUtils.nextTick();

assert.containsOnce(document.body, '.modal', "the quick_create modal should appear");

await testUtils.dom.click($('.modal .btn-primary:first'));
await testUtils.dom.click(document.body);

assert.strictEqual(list.el.getElementsByClassName('o_data_cell')[0].innerHTML, "aaa",
"value should have been updated");

list.destroy();
});


QUnit.test('float field render with digits attribute on listview', async function (assert) { QUnit.test('float field render with digits attribute on listview', async function (assert) {
assert.expect(1); assert.expect(1);
Expand Down

0 comments on commit 5817f0e

Please sign in to comment.