Problem
Consider a TML table as follows:
| *Name* | *Value* |
%SEARCH{"search expression"
format="| $formfield(Name) | $formfield(Value) |"
}%
If the
$formfield(Value)
contains any newlines, it will break up the TML table.
Solution 1: Use HTML tables
Example:
<table class="foswikiTable" border="1" rules="rows">
<tr><th> *Name* </th><th> *Value* </th></tr>
%SEARCH{"search expression"
format="<tr><td> $formfield(Name) </td><td> $formfield(Value) </td></tr>"
}%
</table>
The problem is that this table, while it will look similar to a table created from TML markup, will not have clickable column headings to apply sorting. To work around this, use
JQTablePlugin to enable sorting of table columns in the browser using javascript.
Solution 2: Use %SUBST%
from FilterPlugin
Replace occurrences of newlines with
<br/>
NB: Should also deal with stray | and replace with
&vbar;
This is untested! Please improve this example by testing and/or correcting:
| *Name* | *Value* |
%SEARCH{"search expression"
format="| $formfield(Name) | $percntSUBST{text=\"$formfield(Value)\" pattern=\"([\r\n]+)\" format=\"<br />\"}$percnt |"
}%
NB: Should also deal with stray | and replace with
&vbar;
This is untested! Please improve this example by testing and/or correcting:
| *Name* | *Value* |
%SEARCH{"search expression"
format="| $formfield(Name) | $percntFORMATLIST{\"$formfield(Value)\" split=\"[\r\n]+\" separator=\"<br />\"}$percnt |"
}%
Solution 3: Use %ENCODE%
macro (Foswiki 1.1+)
Replace occurances of newlines with
This is untested! Please improve this example by testing and/or correcting:
| *Name* | *Value* |
%SEARCH{"search expression"
format="| $formfield(Name) | $percntENCODE{\"$formfield(Value)\" old=\"|,$dollarn\" new=\"&vbar;,<br />\"}$percnt |"
}%
Solution 4: Replace textarea formfield type
This work is not available yet. If somebody were to publish something it would be in the form of a plugin that provides a new formfield type that when rendered via
$formfield()
would emit newlines as
--
PaulHarvey - 11 May 2010