[FIX] web: Prevent quick create from closing after text selection
There is a function allowing to close the quick create if we click outside the element. `RecordQuickCreate._onWindowClicked` Except that this function is triggered in a "click" event, so if we click on the quick create element and drag the mouse outside, it will detect that we are outside and close the quick create. This manipulation can happen when you want to select text with the mouse. This PR prevents this behavior by detecting when a click is from the quick create opw-2558932 closes odoo/odoo#72279 X-original-commit: 75538bf2a36aa91df8b183ac21ae99a174e1c2fa Signed-off-by: Achraf <abz-odoo@users.noreply.github.com>
This commit is contained in:
@@ -21,7 +21,9 @@ var RecordQuickCreate = Widget.extend({
|
||||
'click .o_kanban_add': '_onAddClicked',
|
||||
'click .o_kanban_edit': '_onEditClicked',
|
||||
'click .o_kanban_cancel': '_onCancelClicked',
|
||||
'mousedown': '_onMouseDown',
|
||||
},
|
||||
mouseDownInside: false,
|
||||
|
||||
/**
|
||||
* @override
|
||||
@@ -255,6 +257,9 @@ var RecordQuickCreate = Widget.extend({
|
||||
* @param {MouseEvent} ev
|
||||
*/
|
||||
_onWindowClicked: function (ev) {
|
||||
var mouseDownInside = this.mouseDownInside;
|
||||
|
||||
this.mouseDownInside = false;
|
||||
// ignore clicks if the quick create is not in the dom
|
||||
if (!document.contains(this.el)) {
|
||||
return;
|
||||
@@ -288,12 +293,21 @@ var RecordQuickCreate = Widget.extend({
|
||||
}
|
||||
|
||||
// ignore clicks if target is inside the quick create
|
||||
if (this.el.contains(ev.target) || this.el === ev.target) {
|
||||
if (this.el.contains(ev.target) || this.el === ev.target || mouseDownInside) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.cancel();
|
||||
},
|
||||
/**
|
||||
* Detects if the click is originally from the quick create
|
||||
*
|
||||
* @private
|
||||
* @param {MouseEvent} ev
|
||||
*/
|
||||
_onMouseDown: function(ev){
|
||||
this.mouseDownInside = true;
|
||||
}
|
||||
});
|
||||
|
||||
return RecordQuickCreate;
|
||||
|
||||
@@ -936,7 +936,7 @@ QUnit.module('Views', {
|
||||
});
|
||||
|
||||
QUnit.test('quick create record: cancel and validate without using the buttons', async function (assert) {
|
||||
assert.expect(8);
|
||||
assert.expect(9);
|
||||
|
||||
var nbRecords = 4;
|
||||
var kanban = await createView({
|
||||
@@ -972,6 +972,14 @@ QUnit.module('Views', {
|
||||
assert.containsNone(kanban, '.o_kanban_quick_create',
|
||||
"the quick create should be destroyed when the user clicks outside");
|
||||
|
||||
// click to input and drag the mouse outside, should not cancel the quick creation
|
||||
await testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first());
|
||||
$quickCreate = kanban.$('.o_kanban_quick_create');
|
||||
await testUtils.dom.triggerMouseEvent($quickCreate.find('input'), 'mousedown');
|
||||
await testUtils.dom.click(kanban.$('.o_kanban_group .o_kanban_record:first').first());
|
||||
assert.containsOnce(kanban, '.o_kanban_quick_create',
|
||||
"the quick create should not have been destroyed after clicking outside");
|
||||
|
||||
// click to really add an element
|
||||
await testUtils.dom.click(kanban.$('.o_kanban_header .o_kanban_quick_add i').first());
|
||||
$quickCreate = kanban.$('.o_kanban_quick_create');
|
||||
|
||||
Reference in New Issue
Block a user