summaryrefslogtreecommitdiff
path: root/addons/web_editor/static/src
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2019-12-05 13:28:53 +0000
committerqsm-odoo <qsm@odoo.com>2019-12-06 09:45:30 +0000
commite4d4aab04270be71ffde9b1fe8ffc1d34217d663 (patch)
tree845c334e39bc705443cbe94af196cbdea1d87c05 /addons/web_editor/static/src
parent65262c5e3e1550e4dfe6d6629af532dda6cc240f (diff)
[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
Diffstat (limited to 'addons/web_editor/static/src')
-rw-r--r--addons/web_editor/static/src/js/editor/snippets.options.js39
1 files 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');
},
});