mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
make t-set works with t-props
test by aku, fix by ged
This commit is contained in:
committed by
Géry Debongnie
parent
733d5f81e6
commit
9be0b65cd3
+6
-3
@@ -511,7 +511,7 @@ export class QWeb {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_formatExpression(e: string): string {
|
_formatExpression(e: string, ctx?: Context): string {
|
||||||
if (e in this.exprCache) {
|
if (e in this.exprCache) {
|
||||||
return this.exprCache[e];
|
return this.exprCache[e];
|
||||||
}
|
}
|
||||||
@@ -537,7 +537,10 @@ export class QWeb {
|
|||||||
} else if (c.match(/\W/) && invar.length) {
|
} else if (c.match(/\W/) && invar.length) {
|
||||||
// TODO: Should check for possible spaces before dot
|
// TODO: Should check for possible spaces before dot
|
||||||
if (chars[invarPos - 1] !== "." && RESERVED_WORDS.indexOf(invar) < 0) {
|
if (chars[invarPos - 1] !== "." && RESERVED_WORDS.indexOf(invar) < 0) {
|
||||||
invar = WORD_REPLACEMENT[invar] || "context['" + invar + "']";
|
invar =
|
||||||
|
WORD_REPLACEMENT[invar] ||
|
||||||
|
(ctx && invar in ctx.variables && ctx.variables[invar]) ||
|
||||||
|
"context['" + invar + "']";
|
||||||
}
|
}
|
||||||
r += invar;
|
r += invar;
|
||||||
invar = "";
|
invar = "";
|
||||||
@@ -847,7 +850,7 @@ const widgetDirective: Directive = {
|
|||||||
if (!val) {
|
if (!val) {
|
||||||
val = key;
|
val = key;
|
||||||
}
|
}
|
||||||
return `${key}: ${qweb._formatExpression(val)}`;
|
return `${key}: ${qweb._formatExpression(val, ctx)}`;
|
||||||
})
|
})
|
||||||
.join(",");
|
.join(",");
|
||||||
props = "{" + innerProp + "}";
|
props = "{" + innerProp + "}";
|
||||||
|
|||||||
@@ -787,6 +787,27 @@ describe("props evaluation (with t-props directive)", () => {
|
|||||||
await widget.mount(fixture);
|
await widget.mount(fixture);
|
||||||
expect(fixture.innerHTML).toBe("<div><span>hello aaron</span></div>");
|
expect(fixture.innerHTML).toBe("<div><span>hello aaron</span></div>");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-set works with t-props", async () => {
|
||||||
|
class Parent extends Widget {
|
||||||
|
inlineTemplate = `
|
||||||
|
<div>
|
||||||
|
<t t-set="val" t-value="42"/>
|
||||||
|
<t t-widget="child" t-props="{val:val}"/>
|
||||||
|
</div>`;
|
||||||
|
widgets = { child: Child }
|
||||||
|
}
|
||||||
|
class Child extends Widget {
|
||||||
|
inlineTemplate = `
|
||||||
|
<span>
|
||||||
|
<t t-esc="props.val"/>
|
||||||
|
</span>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const widget = new Parent(env);
|
||||||
|
await widget.mount(fixture);
|
||||||
|
expect(normalize(fixture.innerHTML)).toBe("<div><span>42</span></div>");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("other directives with t-widget", () => {
|
describe("other directives with t-widget", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user