From e4dda761ed6e55695da0bae66ed08c4a7ecf9eb5 Mon Sep 17 00:00:00 2001 From: "Simon Genin (ges)" Date: Thu, 18 Jan 2024 12:24:20 +0000 Subject: [PATCH] [FIX] web: kanban column quick create validates on enter When creating a new column in kanban view, the user should be able to either hit enter or click the add button. This launched the validation process to add the column. There has been a fix in owl that would force a t-model.trim to be lazy. This was causing problems in this case as the "enter" pressed by the user was detected through the hotkey system. This was causing the change event not to fire, resulting in the behavior of the feature being broken. We fix this by using the t-on-keydown directive instead of the hotkey. We also remove the t-model directive as it is no longer of any use. The trim is done in the validate function. task id 3691208 closes odoo/odoo#150297 X-original-commit: e3ad26632b00d0b0dded25282e4dc910983ef9dc Signed-off-by: Aaron Bohy (aab) Signed-off-by: Simon Genin (ges@odoo) --- .../kanban/kanban_column_quick_create.js | 21 ++++++----- .../kanban/kanban_column_quick_create.xml | 2 +- .../tests/views/kanban/kanban_view_tests.js | 36 +++++++++++++++++++ 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/addons/web/static/src/views/kanban/kanban_column_quick_create.js b/addons/web/static/src/views/kanban/kanban_column_quick_create.js index 785b0116b6e..d431bfb2ca4 100644 --- a/addons/web/static/src/views/kanban/kanban_column_quick_create.js +++ b/addons/web/static/src/views/kanban/kanban_column_quick_create.js @@ -12,10 +12,11 @@ export class KanbanColumnQuickCreate extends Component { this.dialog = useService("dialog"); this.root = useRef("root"); this.state = useState({ - columnTitle: "", + hasInputFocused: false, }); useAutofocus(); + this.inputRef = useRef("autofocus"); // Close on outside click useExternalListener(window, "mousedown", (/** @type {MouseEvent} */ ev) => { @@ -38,11 +39,6 @@ export class KanbanColumnQuickCreate extends Component { ); // Key Navigation - const inputRef = useRef("autofocus"); - useHotkey("enter", () => this.validate(), { - area: () => inputRef.el, - bypassEditableProtection: true, - }); useHotkey("escape", () => this.fold()); } @@ -65,9 +61,10 @@ export class KanbanColumnQuickCreate extends Component { } validate() { - if (this.state.columnTitle.length) { - this.props.onValidate(this.state.columnTitle); - this.state.columnTitle = ""; + const title = this.inputRef.el.value.trim(); + if (title.length) { + this.props.onValidate(title); + this.inputRef.el.value = ""; } } @@ -88,6 +85,12 @@ export class KanbanColumnQuickCreate extends Component { }, }); } + + onInputKeydown(ev) { + if (ev.key === "Enter") { + this.validate(); + } + } } KanbanColumnQuickCreate.props = { exampleData: [Object, { value: null }], diff --git a/addons/web/static/src/views/kanban/kanban_column_quick_create.xml b/addons/web/static/src/views/kanban/kanban_column_quick_create.xml index ddf5500326a..2e1e3e3ddff 100644 --- a/addons/web/static/src/views/kanban/kanban_column_quick_create.xml +++ b/addons/web/static/src/views/kanban/kanban_column_quick_create.xml @@ -15,9 +15,9 @@ class="form-control bg-view" t-attf-placeholder="{{ relatedFieldName }}..." t-ref="autofocus" - t-model.trim="state.columnTitle" t-on-focus="() => state.hasInputFocused = true" t-on-blur="() => state.hasInputFocused = false" + t-on-keydown="onInputKeydown" />