[FIX] qweb: handle input value attribute as a property

Sometimes, HTML is slightly more subtle than what I initially expect.
Rendering some html is simple, we have tags and attributes.  However,
once we add behaviour, then the situation is more complex:

<input value="abc"/>

is an input with an INITIAL value of "abc", but the attribute does not
actually represent the CURRENT value of the input, which may be
different if the user did change it.

This is basically the difference between "attribute" and "property".

So, when rendering html with owl, we sometimes want to actually set
the property (current value), instead of the html attribute.

This commit make sure that this is the case for inputs with the "value"
attribute.

closes #722
This commit is contained in:
Géry Debongnie
2020-09-16 22:00:31 +02:00
committed by aab-odoo
parent 3bf91afc3f
commit e5e7790530
3 changed files with 27 additions and 5 deletions
+6 -3
View File
@@ -668,7 +668,7 @@ export class QWeb extends EventBus {
const props: string[] = [];
const tattrs: number[] = [];
function handleBooleanProps(key, val) {
function handleProperties(key, val) {
let isProp = false;
if (node.nodeName === "input" && key === "checked") {
let type = (<Element>node).getAttribute("type");
@@ -676,6 +676,9 @@ export class QWeb extends EventBus {
isProp = true;
}
}
if (node.nodeName === "input" && key === "value") {
isProp = true;
}
if (node.nodeName === "option" && key === "selected") {
isProp = true;
}
@@ -722,7 +725,7 @@ export class QWeb extends EventBus {
name = '"' + name + '"';
}
attrs.push(`${name}: _${attID}`);
handleBooleanProps(name, attID);
handleProperties(name, attID);
}
}
@@ -759,7 +762,7 @@ export class QWeb extends EventBus {
}
ctx.addLine(`let _${attID} = ${formattedValue};`);
attrs.push(`${attName}: _${attID}`);
handleBooleanProps(attName, attID);
handleProperties(attName, attID);
}
}