Item12868: SEARCH newline parameter does not apply to ItemTemplatefield content
Priority: Urgent
Current State: Closed
Released In: 2.0.0
Target Release: major
Applies To: Engine
Component: SEARCH
Branches: master
I'm porting from TWiki and have a SEARCH that I am formatting into a table, the SEARCH queries a form where one of the fields contains a bulleted list. I need this bulleted list to render correctly within the containing table. This is challenging in Foswiki for two reasons; first, new lines returned from a $formfield are always transformed to <br />, which breaks rendering of the the bulleted list, and second, even if $formfield produced raw new lines those would break the render of the TML table.
related:
I solved the TML table rendering issue by installing
TWiki's RecursiveRenderPlugin and using its <render> tag; the installation was unfortunately challenging since it has not been ported to Foswiki yet.
It is then possible to work-around the newline/$formfield issue by embedding a QUERY for the raw value into the SEARCH format:
%SEARCH{
"Role$"
scope="topic"
type="regex"
nonoise="on"
header="| *Name* | *Purpose* | *Energizers* |"
format="| [[$topic][$formfield(Name)]] | <render>$percentQUERY{\"'$topic'/Purpose\"}$percent</render> | <render>$percentQUERY{\"'$topic'/Energizers\"}$percent</render> |"
}%
I find this nested QUERY unnecessarily complex and would much prefer for the newline parameter to apply to $formfield so I could do this:
%SEARCH{
"Role$"
scope="topic"
type="regex"
nonoise="on"
newline="$n"
header="| *Name* | *Purpose* | *Energizers* |"
format="| [[$topic][$formfield(Name)]] | <render>$formfield(Purpose)</render> | <render>$formfield(Energizers)</render> |"
}%
I'm attaching my suggested patch for this issue, created on
http://svn.foswiki.org/tags/FoswikiRelease01x01x09. This patch updates SEARCH.pm to pass the value of the newline parameter along to Foswiki::Meta::renderFormFieldForDisplay as an attribute. During execution Foswiki::Render::protectFormFieldValue is called, and it already has code to complete the replacement. If no newline parameter is provided, then the current default behavior is maintained--new lines are replaced with <br / >.
Also included in the patch are the related changes to documentation, and uncommenting
CrawfordCurrie's unit test for this feature.
This patch works on my 1.1.9 install. I don't have a functioning test environment so I have not verified the unit test.
--
DavidAllen - 26 Apr 2014
Marking this as urgent so that it gets considered for 1.2 in the tasks review.
--
GeorgeClark - 29 May 2014
Good patch. Thanks
DavidAllen.
--
CrawfordCurrie - 05 Nov 2014