allow static and dynamic attributes to combine in qweb

This commit is contained in:
Géry Debongnie
2019-03-04 11:24:35 +01:00
parent ca32d8b856
commit 0983ff0d24
4 changed files with 30 additions and 3 deletions
+9 -1
View File
@@ -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 = (<Element>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}`);
}
+2 -2
View File
@@ -11,8 +11,8 @@
<div class="o_loading d-none" t-ref="loading_indicator">Loading</div>
</div>
<div t-name="web.navbar" class="o_navbar" t-att-class="props.inHome ? 'o_navbar o_in_home' : 'o_navbar'">
<a aria-label="Applications" t-if="!props.inHome || props.app" t-att-class="props.inHome ? 'o_title fa fa-chevron-left' : 'o_title fa fa-th'" href="#" title="Applications" accesskey="h" t-on-click="toggleHome"/>
<div t-name="web.navbar" class="o_navbar" t-att-class="props.inHome ? 'o_in_home' : ''">
<a aria-label="Applications" t-if="!props.inHome || props.app" class="o_title fa" t-att-class="props.inHome ? 'fa-chevron-left' : 'fa-th'" href="#" title="Applications" accesskey="h" t-on-click="toggleHome"/>
<t t-if="!props.inHome &amp;&amp; props.app">
<a class="o_menu_brand" t-att-href="getUrl(props.app)" role="button" t-on-click="openMenu(props.app)">
<t t-esc="props.app.name"/>