Skip to content

Commit

Permalink
[FIX] web_editor: update all values when using up/down on multi-value
Browse files Browse the repository at this point in the history
When using the up/down arrows in an `InputUserValueWidget`, only the
first value is updated but the other ones are lost.

This commit adapts the behavior so that all parts of the composite value
are updated.
When decreasing, parts that have reached zero are set to zero.

Steps to reproduce:
- Drop a "Banner" snippet.
- Select the text block.
- Set the "Border" option to "5 10".
- Press the up or down key.

=> Only the "5" was updated, the "10" was lost.

task-3800288

closes #159331

X-original-commit: 3c2eabb
Signed-off-by: Robin Lejeune (role) <role@odoo.com>
Signed-off-by: Benoit Socias (bso) <bso@odoo.com>
  • Loading branch information
bso-odoo committed Mar 27, 2024
1 parent c6450d7 commit 7e3267f
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions addons/web_editor/static/src/js/editor/snippets.options.js
Expand Up @@ -1313,16 +1313,26 @@ const InputUserValueWidget = UnitUserValueWidget.extend({
case $.ui.keyCode.UP:
case $.ui.keyCode.DOWN: {
const input = ev.currentTarget;
let value = parseFloat(input.value || input.placeholder);
if (isNaN(value)) {
value = 0.0;
let parts = (input.value || input.placeholder).match(/-?\d+\.\d+|-?\d+/g);
if (!parts) {
parts = [input.value || input.placeholder];
}
let step = parseFloat(params.step);
if (isNaN(step)) {
step = 1.0;
}
value += (ev.which === $.ui.keyCode.UP ? step : -step);
input.value = this._floatToStr(value);
input.value = parts.map(part => {
let value = parseFloat(part);
if (isNaN(value)) {
value = 0.0;
}
let step = parseFloat(params.step);
if (isNaN(step)) {
step = 1.0;
}
value += (ev.which === $.ui.keyCode.UP ? step : -step);
if (parts.length > 1 && value < 0) {
// No negative for composite values.
value = 0.0;
}
return this._floatToStr(value);
}).join(" ");
// We need to know if the change event will be triggered or not.
// Change is triggered if there has been a "natural" input event
// from the user. Since we are triggering a "fake" input event,
Expand Down

0 comments on commit 7e3267f

Please sign in to comment.