How do I stop a FormattedSearch using $formfield() from breaking TML tables?

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 |"
}%

Solution 2.1: Use %FORMATLIST% from FilterPlugin

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

  • Set NOWYSIWYG = 1

Support.FAQForm edit

TopicClassification FrequentlyAskedQuestion
Subject Search
Topic Summary Tables constructed with TML markup are sensitive to newlines, so usage of $formfield() values containing them demands special attention
Extension
Interested Parties
Related Topics
Topic revision: r2 - 27 Dec 2011, ArthurClemens - This page was cached on 17 May 2017 - 08:28.

The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License