Formula – XHTML

There are small number of scenarios that go way beyond rich capabilities provided by TeamDesk. One is conditional formatting of column's values.

Formula – XHTML is introduced to provide the way to decorate the value with tags and styles. It is a mixture of limited (X)HTML markup and TeamDesk formula language.

Using Formula – XHTML you can write HTML markup as is, decorating TeamDesk formula pieces (code points) with <%…%> marks; those of you who dealt with ASP should be familiar with the syntax. Each formula piece is evaluated, the result of evaluation is properly encoded and inserted in the markup.

Code points can appear inside attribute values and/or in tag contents, no dynamic tag generation is allowed. We designed it this way to ensure the formula result is a well formed HTML and won't affect the rest of page's content.

Here are typical usage examples for the formula:

1. Decorate contacts name as a e-mail link:

<a href="<% Nz("mailto:" & [E-Mail]) %>"><% [Name] %></a>

Behind the scenes Formula – XHTML creates text formula: a concatenation of markup code and formula results enclosed in HTML encoding function, such as the code below produced from the example:

"<a href=\"" & Encode(Nz("mailto:" & [E-Mail])) & "\">" & Encode([Name]) & "</a>"

2. Color the value red if it is less than 100:

<span style="<% If([Value] < 100, "color:red", "") %>">
<%= [Value] %>

Be aware of the way concatenation handles NULL values – if one of the parts is NULL whole result is also NULL – first example produce no markup at all when the value of [Name] is blank. While it is useful in some scenarios, enclosing each and every field you want to display in a sort of NULL checks is a cumbersome task. To handle this case we created a shorthand for code points containing a sole reference to a column, a <%= [Column] %>. It creates Nz() wrapper so that NULL values produce empty strings that can be safely concatenated; numbers, dates, times and timestamps are converted to text via locale-aware Format() function, other types converted via ToText(). In second example, <%= [Value] %> produces Encode(Nz(Format( [Value] ))).

The usage of HTML and Formula – XHTML is somewhat limited due to technical reasons.

1. Markup will be displayed as text in:

  • Dropdown lists, as dropdowns do not support markup;
  • Calendar views and Lookup columns with "Display As Link" options checked, as very limited set of tags can be displayed inside of link;
  • Documents as Word file format has no connection to HTML;

2. Some tags are disabled to avoid interference with the rest of the page:

<html>, <head>, <script>, <noscript>, <title>, <meta>, <link>, <base>, <style>, <body>, <form>, <input>, <isindex>, <textarea>, <select>, <optgroup>, <option>, <fieldset>, <legend>.

<button> tag is allowed only when its type attribute is set to "button".

3. All allowed tags require closing tag, even if it is not required by HTML. For example, in HTML you can write:

<p>First paragraph
<p>Second paragraph

In formula code you should closing </p> tag before opening new <p> tag:

<p>First paragraph</p>
<p>Second paragraph</p>

4. Tags that can not have inner content, such as <img>, <br>, <hr> and <param> should be self-closed, e.g. written as <br/> or <img src="image.gif"/>

Tweet about this on TwitterShare on Facebook0Share on Google+0