Using FORMFIELD to replace items in a list

Q: I would like to lookup items in a list using FORMFIELD and output the list if the fields so found. (See TWikiVariables#FORMFIELD_fieldname_renders_a_fi to learn about FORMFIELD and TWikiForms to learn about forms.)

A: Going through a list and processing each element in the list is possible within the SpreadSheetPlugin. There you can find a $LISTMAP() function which goes through a list item by item, and produces a modified list, see SpreadSheetPlugin#LISTMAP_formula_list_evaluate_an. (List items are separated by a comma and a space.). Example:

%CALC{ "$LISTMAP($NOP(%)FORMFIELD{\"fld\" topic=\"$item\"}$NOP(%), WikiName1, WikiName2, WikiName3)" }%

In the above example, one assumes that there are topics WikiName1, WikiName2 and WikiName3 which contain a form, where there is a field called fld. The expression (I hope) produces a list of three items which are the contents of the fld fields in the respective topics.

The nontrivial thing here is that without the $NOP($) quotings the FORMFIELD{} would be evaluated too early. The normal order of evaluation is the same as in most programming languages, i.e. parameters first, and the FORMFIELD is a parameter to the LISTMAP. The quoting defers this evaluation until each list item is at hand.

-- KimmoKoskenniemi - 18 May 2007

Topic revision: r1 - 2007-05-18 - KimmoKoskenniemi
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback