mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] blockdom: t-att- correcltly sets the value to zero
In 3536f41f00 we added a fallback when setting a
property to a falsy value so that the property was set to the empty string. The
objective being to not get the string "undefined"/"null"/"false" as property
value. However, using t-att- to set a property to 0 is perfectly reasonable and
in fact quite common.
This commit is contained in:
committed by
aab-odoo
parent
77ff5ee895
commit
d277039b14
@@ -139,7 +139,8 @@ export function updateClass(this: HTMLElement, val: any, oldVal: any) {
|
|||||||
|
|
||||||
export function makePropSetter(name: string): Setter<HTMLElement> {
|
export function makePropSetter(name: string): Setter<HTMLElement> {
|
||||||
return function setProp(this: HTMLElement, value: any) {
|
return function setProp(this: HTMLElement, value: any) {
|
||||||
(this as any)[name] = value || "";
|
// support 0, fallback to empty string for other falsy values
|
||||||
|
(this as any)[name] = value === 0 ? 0 : value || "";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -169,13 +169,25 @@ describe("properties", () => {
|
|||||||
expect(input.value).toBe("potato");
|
expect(input.value).toBe("potato");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("input with value attribute, and undefined given", () => {
|
test("input with value attribute, and falsy value given", () => {
|
||||||
const block = createBlock(`<input block-attribute-0="value"/>`);
|
const block = createBlock(`<input block-attribute-0="value"/>`);
|
||||||
|
|
||||||
const tree = block([undefined]);
|
const tree = block([undefined]);
|
||||||
mount(tree, fixture);
|
mount(tree, fixture);
|
||||||
const input = fixture.querySelector("input")!;
|
const input = fixture.querySelector("input")!;
|
||||||
expect(input.value).toBe("");
|
expect(input.value).toBe("");
|
||||||
|
|
||||||
|
patch(tree, block([null]));
|
||||||
|
expect(input.value).toBe("");
|
||||||
|
|
||||||
|
patch(tree, block([0]));
|
||||||
|
expect(input.value).toBe("0");
|
||||||
|
|
||||||
|
patch(tree, block([""]));
|
||||||
|
expect(input.value).toBe("");
|
||||||
|
|
||||||
|
patch(tree, block([false]));
|
||||||
|
expect(input.value).toBe("");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("input type=checkbox with checked attribute", () => {
|
test("input type=checkbox with checked attribute", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user