mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] qweb: bind handlers to component
Before this commit, the handlers were bound to the current context, which is often the component but not necessarily. In some cases, a sub scope can be created (with t-foreach, or slots, or t-call), and the context is actually an object with the actual component instance it its prototype chain, but not the component.
This commit is contained in:
+33
-1
@@ -1120,7 +1120,7 @@ describe("misc", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe.only("t-on", () => {
|
||||
describe("t-on", () => {
|
||||
test("can bind event handler", () => {
|
||||
qweb.addTemplate("test", `<button t-on-click="add">Click</button>`);
|
||||
let a = 1;
|
||||
@@ -1324,6 +1324,38 @@ describe.only("t-on", () => {
|
||||
expect(owner.state.n).toBe(4);
|
||||
});
|
||||
|
||||
test("t-on with t-call", async () => {
|
||||
expect.assertions(2);
|
||||
qweb.addTemplate("sub", `<p t-on-click="update">lucas</p>`);
|
||||
qweb.addTemplate("main", `<div><t t-call="sub"/></div>`);
|
||||
|
||||
let owner = {
|
||||
update() {
|
||||
expect(this).toBe(owner);
|
||||
}
|
||||
};
|
||||
|
||||
const node = renderToDOM(qweb, "main", owner, { handlers: [] });
|
||||
(<HTMLElement>node).querySelector("p")!.click();
|
||||
});
|
||||
|
||||
test("t-on, with arguments and t-call", async () => {
|
||||
expect.assertions(3);
|
||||
qweb.addTemplate("sub", `<p t-on-click="update(value)">lucas</p>`);
|
||||
qweb.addTemplate("main", `<div><t t-call="sub"/></div>`);
|
||||
|
||||
let owner = {
|
||||
update(val) {
|
||||
expect(this).toBe(owner);
|
||||
expect(val).toBe(444);
|
||||
},
|
||||
value: 444
|
||||
};
|
||||
|
||||
const node = renderToDOM(qweb, "main", owner, { handlers: [] });
|
||||
(<HTMLElement>node).querySelector("p")!.click();
|
||||
});
|
||||
|
||||
test("t-on with prevent and/or stop modifiers", async () => {
|
||||
expect.assertions(7);
|
||||
qweb.addTemplate(
|
||||
|
||||
Reference in New Issue
Block a user