mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] compiler: fix falsy values for properties not keeping input empty
Recently, we made it so that when a component is rendered, it always updates the property values for computed properties. This was done by wrapping the value in a String or Boolean object. One issue with this is that wrapping a falsy value in a String doesn't yield an empty string, but a string containing the value as text (eg new String(undefined) -> "undefined"), which causes the value to not remain empty as per the spec. This commit fixes that by adding a fallback to the empty string for falsy values before converting to a String object. closes: #1236
This commit is contained in:
committed by
aab-odoo
parent
d3b0d1971e
commit
02a187d80b
@@ -329,6 +329,35 @@ describe("attributes", () => {
|
||||
expect(fixture.innerHTML).toBe('<div value=""></div>');
|
||||
});
|
||||
|
||||
test("updating property with falsy value", async () => {
|
||||
// render input with initial value
|
||||
const template = `<input t-att-value="v"></input>`;
|
||||
const bnode1 = renderToBdom(template, { v: false });
|
||||
const fixture = makeTestFixture();
|
||||
mount(bnode1, fixture);
|
||||
|
||||
const input = fixture.querySelector("input")!;
|
||||
expect(input.value).toBe("");
|
||||
|
||||
patch(bnode1, renderToBdom(template, { v: "owl" }));
|
||||
expect(input.value).toBe("owl");
|
||||
|
||||
patch(bnode1, renderToBdom(template, { v: false }));
|
||||
expect(input.value).toBe("");
|
||||
|
||||
patch(bnode1, renderToBdom(template, { v: "owl" }));
|
||||
expect(input.value).toBe("owl");
|
||||
|
||||
patch(bnode1, renderToBdom(template, { v: undefined }));
|
||||
expect(input.value).toBe("");
|
||||
|
||||
patch(bnode1, renderToBdom(template, { v: "owl" }));
|
||||
expect(input.value).toBe("owl");
|
||||
|
||||
patch(bnode1, renderToBdom(template, { v: null }));
|
||||
expect(input.value).toBe("");
|
||||
});
|
||||
|
||||
test("changing a class with t-att-class", () => {
|
||||
// render input with initial value
|
||||
const template = `<div t-att-class="v"/>`;
|
||||
|
||||
Reference in New Issue
Block a user