mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[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:
@@ -1876,6 +1876,25 @@ describe("special cases for some boolean html attributes/properties", () => {
|
||||
);
|
||||
renderToString(qweb, "test", { flag: true });
|
||||
});
|
||||
|
||||
test("input with t-att-value", () => {
|
||||
// render input with initial value
|
||||
qweb.addTemplate("test", `<input t-att-value="v"/>`);
|
||||
const vnode1 = qweb.render("test", { v: "zucchini" });
|
||||
const vnode2 = patch(document.createElement("input"), vnode1);
|
||||
let elm = vnode2.elm as HTMLInputElement;
|
||||
expect(elm.value).toBe("zucchini");
|
||||
|
||||
// change value manually in input, to simulate user input
|
||||
elm.value = "tomato";
|
||||
expect(elm.value).toBe("tomato");
|
||||
|
||||
// rerender with a different value, and patch actual dom, to check that
|
||||
// input value was properly reset by owl
|
||||
const vnode3 = qweb.render("test", { v: "potato" });
|
||||
patch(vnode2, vnode3);
|
||||
expect(elm.value).toBe("potato");
|
||||
});
|
||||
});
|
||||
|
||||
describe("whitespace handling", () => {
|
||||
|
||||
Reference in New Issue
Block a user