From e4d4aab04270be71ffde9b1fe8ffc1d34217d663 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Thu, 5 Dec 2019 13:28:53 +0000 Subject: [PATCH] [IMP] web_editor: validate input entry with ENTER in editor left panel Especially useful with a no-preview input. Part of https://github.com/odoo/odoo/pull/41402 --- .../static/src/js/editor/snippets.options.js | 39 +++++++++---------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/snippets.options.js b/addons/web_editor/static/src/js/editor/snippets.options.js index 75eae90896d..28a885fbfce 100644 --- a/addons/web_editor/static/src/js/editor/snippets.options.js +++ b/addons/web_editor/static/src/js/editor/snippets.options.js @@ -318,6 +318,7 @@ const UserValueWidget = Widget.extend({ if (this._canUpdateUI()) { await this._updateUI(); } + this._validating = false; }, //-------------------------------------------------------------------------- @@ -334,7 +335,8 @@ const UserValueWidget = Widget.extend({ _canUpdateUI: function () { const focusEl = document.activeElement; if (focusEl && focusEl.tagName === 'INPUT' - && (this.el === focusEl || this.el.contains(focusEl))) { + && (this.el === focusEl || this.el.contains(focusEl)) + && !this._validating) { return false; } return true; @@ -790,32 +792,29 @@ const InputUserValueWidget = UserValueWidget.extend({ * @param {Event} ev */ _onInputKeydown: function (ev) { - const input = ev.currentTarget; - let value = parseFloat(input.value || input.placeholder); - if (isNaN(value)) { - return; - } - - let step = parseFloat(input.parentNode.dataset.step); - if (isNaN(step)) { - step = 1.0; - } switch (ev.which) { - case $.ui.keyCode.UP: { - value += step; + case $.ui.keyCode.ENTER: { + this._validating = true; + this._onUserValueChange(ev); break; } + case $.ui.keyCode.UP: case $.ui.keyCode.DOWN: { - value -= step; + const input = ev.currentTarget; + let value = parseFloat(input.value || input.placeholder); + if (isNaN(value)) { + return; + } + let step = parseFloat(input.parentNode.dataset.step); + if (isNaN(step)) { + step = 1.0; + } + value += (ev.which === $.ui.keyCode.UP ? step : -step); + input.value = `${parseFloat(value.toFixed(3))}`; + $(input).trigger('input'); break; } - default: { - return; - } } - - input.value = `${parseFloat(value.toFixed(3))}`; - $(input).trigger('input'); }, });