mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
+12
-2
@@ -522,7 +522,10 @@ export class QWeb {
|
|||||||
const value = attributes[i].textContent!;
|
const value = attributes[i].textContent!;
|
||||||
|
|
||||||
// regular attributes
|
// regular attributes
|
||||||
if (!name.startsWith("t-")) {
|
if (
|
||||||
|
!name.startsWith("t-") &&
|
||||||
|
!(<Element>node).getAttribute("t-attf-" + name)
|
||||||
|
) {
|
||||||
const attID = ctx.generateID();
|
const attID = ctx.generateID();
|
||||||
ctx.addLine(`let _${attID} = '${value}';`);
|
ctx.addLine(`let _${attID} = '${value}';`);
|
||||||
if (!name.match(/^[a-zA-Z]+$/)) {
|
if (!name.match(/^[a-zA-Z]+$/)) {
|
||||||
@@ -576,7 +579,14 @@ export class QWeb {
|
|||||||
s => "${" + ctx.formatExpression(s.slice(2, -2)) + "}"
|
s => "${" + ctx.formatExpression(s.slice(2, -2)) + "}"
|
||||||
);
|
);
|
||||||
const attID = ctx.generateID();
|
const attID = ctx.generateID();
|
||||||
ctx.addLine(`let _${attID} = \`${formattedExpr}\`;`);
|
let staticVal = (<Element>node).getAttribute(attName);
|
||||||
|
if (staticVal) {
|
||||||
|
ctx.addLine(
|
||||||
|
`let _${attID} = '${staticVal} ' + \`${formattedExpr}\`;`
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
ctx.addLine(`let _${attID} = \`${formattedExpr}\`;`);
|
||||||
|
}
|
||||||
attrs.push(`${attName}: _${attID}`);
|
attrs.push(`${attName}: _${attID}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -207,6 +207,17 @@ exports[`attributes t-att-class with object 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`attributes t-attf-class should combine with class 1`] = `
|
||||||
|
"function anonymous(context,extra
|
||||||
|
) {
|
||||||
|
let h = this.utils.h;
|
||||||
|
let _1 = 'hello ' + \`world\`;
|
||||||
|
let c2 = [], p2 = {key:2,attrs:{class: _1}};
|
||||||
|
let vn2 = h('div', p2, c2);
|
||||||
|
return vn2;
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`attributes tuple literal 1`] = `
|
exports[`attributes tuple literal 1`] = `
|
||||||
"function anonymous(context,extra
|
"function anonymous(context,extra
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -401,6 +401,12 @@ describe("attributes", () => {
|
|||||||
expect(result).toBe(`<div foo="bar"></div>`);
|
expect(result).toBe(`<div foo="bar"></div>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("t-attf-class should combine with class", () => {
|
||||||
|
qweb.addTemplate("test", `<div class="hello" t-attf-class="world"/>`);
|
||||||
|
const result = renderToString(qweb, "test");
|
||||||
|
expect(result).toBe(`<div class="hello world"></div>`);
|
||||||
|
});
|
||||||
|
|
||||||
test("format value", () => {
|
test("format value", () => {
|
||||||
qweb.addTemplate("test", `<div t-attf-foo="b{{value}}r"/>`);
|
qweb.addTemplate("test", `<div t-attf-foo="b{{value}}r"/>`);
|
||||||
const result = renderToString(qweb, "test", { value: "a" });
|
const result = renderToString(qweb, "test", { value: "a" });
|
||||||
|
|||||||
Reference in New Issue
Block a user