mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
support using object variables in t-esc
This commit is contained in:
+1
-1
@@ -469,7 +469,7 @@ export class QWeb {
|
|||||||
// dynamic attributes
|
// dynamic attributes
|
||||||
if (name.startsWith("t-att-")) {
|
if (name.startsWith("t-att-")) {
|
||||||
let attName = name.slice(6);
|
let attName = name.slice(6);
|
||||||
let formattedValue = this._formatExpression(ctx.getValue(value!));
|
let formattedValue = this._formatExpression(ctx.getValue(value!), ctx);
|
||||||
const attID = ctx.generateID();
|
const attID = ctx.generateID();
|
||||||
if (!attName.match(/^[a-zA-Z]+$/)) {
|
if (!attName.match(/^[a-zA-Z]+$/)) {
|
||||||
// attribute contains 'non letters' => we want to quote it
|
// attribute contains 'non letters' => we want to quote it
|
||||||
|
|||||||
@@ -99,6 +99,20 @@ exports[`attributes format value 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`attributes from object variables set previously 1`] = `
|
||||||
|
"function anonymous(context,extra
|
||||||
|
) {
|
||||||
|
let h = this.utils.h;
|
||||||
|
let c1 = [], p1 = {key:1};
|
||||||
|
let vn1 = h('div', p1, c1);
|
||||||
|
let _2 = {a:'b'}.a;
|
||||||
|
let c3 = [], p3 = {key:3,attrs:{class: _2}};
|
||||||
|
let vn3 = h('span', p3, c3);
|
||||||
|
c1.push(vn3);
|
||||||
|
return vn1;
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`attributes from variables set previously 1`] = `
|
exports[`attributes from variables set previously 1`] = `
|
||||||
"function anonymous(context,extra
|
"function anonymous(context,extra
|
||||||
) {
|
) {
|
||||||
|
|||||||
+3
-6
@@ -410,14 +410,11 @@ describe("attributes", () => {
|
|||||||
expect(result).toBe('<div><span class="def"></span></div>');
|
expect(result).toBe('<div><span class="def"></span></div>');
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip("from object variables set previously", () => {
|
test("from object variables set previously", () => {
|
||||||
// qweb is stupid and does not support this.
|
// Note: standard qweb does not allow 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(
|
qweb.addTemplate(
|
||||||
"test",
|
"test",
|
||||||
`<div t-debug="1"><t t-set="o" t-value="{a:'b'}"/><span t-att-class="o.a"/></div>`
|
`<div><t t-set="o" t-value="{a:'b'}"/><span t-att-class="o.a"/></div>`
|
||||||
);
|
);
|
||||||
const result = renderToString(qweb, "test");
|
const result = renderToString(qweb, "test");
|
||||||
expect(result).toBe('<div><span class="b"></span></div>');
|
expect(result).toBe('<div><span class="b"></span></div>');
|
||||||
|
|||||||
Reference in New Issue
Block a user