mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
qweb: properly deal with dynamic attributes from t-set
This commit is contained in:
@@ -381,7 +381,7 @@ export class QWeb {
|
|||||||
// dynamic attributes
|
// dynamic attributes
|
||||||
if (name.startsWith("t-att-")) {
|
if (name.startsWith("t-att-")) {
|
||||||
const attName = name.slice(6);
|
const attName = name.slice(6);
|
||||||
const formattedValue = this._formatExpression(value!);
|
const formattedValue = this._formatExpression(ctx.getValue(value!));
|
||||||
const attID = ctx.generateID();
|
const attID = ctx.generateID();
|
||||||
ctx.addLine(`let _${attID} = ${formattedValue};`);
|
ctx.addLine(`let _${attID} = ${formattedValue};`);
|
||||||
attrs.push(`${attName}: _${attID}`);
|
attrs.push(`${attName}: _${attID}`);
|
||||||
|
|||||||
@@ -77,6 +77,20 @@ exports[`attributes format value 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`attributes from variables set previously 1`] = `
|
||||||
|
"function anonymous(context,extra
|
||||||
|
) {
|
||||||
|
let h = this.h;
|
||||||
|
let c1 = [], p1 = {};
|
||||||
|
let vn1 = h('div', p1, c1);
|
||||||
|
let _2 = 'def';
|
||||||
|
let c3 = [], p3 = {attrs:{class: _2}};
|
||||||
|
let vn3 = h('span', p3, c3);
|
||||||
|
c1.push(vn3);
|
||||||
|
return vn1;
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`attributes object 1`] = `
|
exports[`attributes object 1`] = `
|
||||||
"function anonymous(context,extra
|
"function anonymous(context,extra
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -353,6 +353,28 @@ describe("attributes", () => {
|
|||||||
expect(result).toBe(`<div foo="bar"></div>`);
|
expect(result).toBe(`<div foo="bar"></div>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("from variables set previously", () => {
|
||||||
|
qweb.addTemplate(
|
||||||
|
"test",
|
||||||
|
`<div><t t-set="abc" t-value="'def'"/><span t-att-class="abc"/></div>`
|
||||||
|
);
|
||||||
|
const result = renderToString(qweb, "test");
|
||||||
|
expect(result).toBe('<div><span class="def"></span></div>');
|
||||||
|
});
|
||||||
|
|
||||||
|
test.skip("from object variables set previously", () => {
|
||||||
|
// qweb is stupid and does not support this.
|
||||||
|
// To do that properly, we need to extend the formatExpression method to
|
||||||
|
// be able to deal with objects. I think that it is not easy:
|
||||||
|
// it should properly deal with stuff like {a:expr, b: {c: otherexpr}}
|
||||||
|
qweb.addTemplate(
|
||||||
|
"test",
|
||||||
|
`<div t-debug="1"><t t-set="o" t-value="{a:'b'}"/><span t-att-class="o.a"/></div>`
|
||||||
|
);
|
||||||
|
const result = renderToString(qweb, "test");
|
||||||
|
expect(result).toBe('<div><span class="b"></span></div>');
|
||||||
|
});
|
||||||
|
|
||||||
test("format expression", () => {
|
test("format expression", () => {
|
||||||
qweb.addTemplate("test", `<div t-attf-foo="{{value + 37}}"/>`);
|
qweb.addTemplate("test", `<div t-attf-foo="{{value + 37}}"/>`);
|
||||||
const result = renderToString(qweb, "test", { value: 5 });
|
const result = renderToString(qweb, "test", { value: 5 });
|
||||||
|
|||||||
Reference in New Issue
Block a user