From 0983ff0d24926fd6a5e29f9a4a9e235b4790b520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Mon, 4 Mar 2019 11:24:35 +0100 Subject: [PATCH] allow static and dynamic attributes to combine in qweb --- web/static/src/ts/core/qweb_vdom.ts | 10 +++++++++- web/static/src/xml/templates.xml | 4 ++-- .../tests/core/__snapshots__/qweb_vdom.test.ts.snap | 13 +++++++++++++ web/static/tests/core/qweb_vdom.test.ts | 6 ++++++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/web/static/src/ts/core/qweb_vdom.ts b/web/static/src/ts/core/qweb_vdom.ts index 503109f2..49b41a07 100644 --- a/web/static/src/ts/core/qweb_vdom.ts +++ b/web/static/src/ts/core/qweb_vdom.ts @@ -406,12 +406,20 @@ export class QWeb { // dynamic attributes if (name.startsWith("t-att-")) { let attName = name.slice(6); - const formattedValue = this._formatExpression(ctx.getValue(value!)); + let formattedValue = this._formatExpression(ctx.getValue(value!)); const attID = ctx.generateID(); if (!attName.match(/^[a-zA-Z]+$/)) { // attribute contains 'non letters' => we want to quote it attName = '"' + attName + '"'; } + // we need to combine dynamic with non dynamic attributes: + // class="a" t-att-class="'yop'" should be rendered as class="a yop" + const attValue = (node).getAttribute(attName); + if (attValue) { + const attValueID = ctx.generateID(); + ctx.addLine(`let _${attValueID} = ${formattedValue};`); + formattedValue = `'${attValue}' + (_${attValueID} ? ' ' + _${attValueID} : '')`; + } ctx.addLine(`let _${attID} = ${formattedValue};`); attrs.push(`${attName}: _${attID}`); } diff --git a/web/static/src/xml/templates.xml b/web/static/src/xml/templates.xml index aa228409..f5579cc5 100644 --- a/web/static/src/xml/templates.xml +++ b/web/static/src/xml/templates.xml @@ -11,8 +11,8 @@
Loading
-