mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
allow non alphanumeric dynamic attributes in qweb
This commit is contained in:
@@ -384,9 +384,13 @@ export class QWeb {
|
|||||||
|
|
||||||
// dynamic attributes
|
// dynamic attributes
|
||||||
if (name.startsWith("t-att-")) {
|
if (name.startsWith("t-att-")) {
|
||||||
const attName = name.slice(6);
|
let attName = name.slice(6);
|
||||||
const formattedValue = this._formatExpression(ctx.getValue(value!));
|
const formattedValue = this._formatExpression(ctx.getValue(value!));
|
||||||
const attID = ctx.generateID();
|
const attID = ctx.generateID();
|
||||||
|
if (!attName.match(/^[a-zA-Z]+$/)) {
|
||||||
|
// attribute contains 'non letters' => we want to quote it
|
||||||
|
attName = '"' + attName + '"';
|
||||||
|
}
|
||||||
ctx.addLine(`let _${attID} = ${formattedValue};`);
|
ctx.addLine(`let _${attID} = ${formattedValue};`);
|
||||||
attrs.push(`${attName}: _${attID}`);
|
attrs.push(`${attName}: _${attID}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,17 @@ exports[`attributes dynamic attribute falsy variable 1`] = `
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`attributes dynamic attribute with a dash 1`] = `
|
||||||
|
"function anonymous(context,extra
|
||||||
|
) {
|
||||||
|
let h = this.h;
|
||||||
|
let _1 = context['id'];
|
||||||
|
let c2 = [], p2 = {attrs:{\\"data-action-id\\": _1}};
|
||||||
|
let vn2 = h('div', p2, c2);
|
||||||
|
return vn2;
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`attributes dynamic attributes 1`] = `
|
exports[`attributes dynamic attributes 1`] = `
|
||||||
"function anonymous(context,extra
|
"function anonymous(context,extra
|
||||||
) {
|
) {
|
||||||
@@ -481,7 +492,7 @@ exports[`misc global 1`] = `
|
|||||||
c1.push({text: \`
|
c1.push({text: \`
|
||||||
\`});
|
\`});
|
||||||
let _7 = 'agüero';
|
let _7 = 'agüero';
|
||||||
let c8 = [], p8 = {attrs:{falló: _7}};
|
let c8 = [], p8 = {attrs:{\\"falló\\": _7}};
|
||||||
let vn8 = h('Año', p8, c8);
|
let vn8 = h('Año', p8, c8);
|
||||||
c1.push(vn8);
|
c1.push(vn8);
|
||||||
c8.push({text: \`
|
c8.push({text: \`
|
||||||
|
|||||||
@@ -309,6 +309,12 @@ describe("attributes", () => {
|
|||||||
expect(result).toBe(`<div foo="bar"></div>`);
|
expect(result).toBe(`<div foo="bar"></div>`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("dynamic attribute with a dash", () => {
|
||||||
|
qweb.addTemplate("test", `<div t-att-data-action-id="id"/>`);
|
||||||
|
const result = renderToString(qweb, "test", { id: 32 });
|
||||||
|
expect(result).toBe(`<div data-action-id="32"></div>`);
|
||||||
|
});
|
||||||
|
|
||||||
test("fixed variable", () => {
|
test("fixed variable", () => {
|
||||||
qweb.addTemplate("test", `<div t-att-foo="value"/>`);
|
qweb.addTemplate("test", `<div t-att-foo="value"/>`);
|
||||||
const result = renderToString(qweb, "test", { value: "ok" });
|
const result = renderToString(qweb, "test", { value: "ok" });
|
||||||
|
|||||||
Reference in New Issue
Block a user