Flexible way to render DataForms
This plugin leverages the internal capabilities to render an interface for DataForms. This API is part of the Form
class of Foswiki and is called renderForEdit()
. It takes a form definition and creates an appropriate edit interface for the given DataFrom. This feature is actually very handy to write custom EDIT_TEMPLATEs and VIEW_TEMPLATEs in wiki applications.
The %RENDEFFOREDIT and %RENDERFORDISPLAY macros allows wiki application authors to customize interfaces to DataForms while not losing the flexibility of defining a DataForm in one place.
Imagine you created an EDIT_TEMPLATE without %RENDERFOREDIT by creating an HTML input form manually. When you decide to extend or modify a form definition later you will always have to maintain these HTML forms in an EDIT_TEMPLATE as well. This redundancy can be avoided by using a %RENDERFOREDIT macro that loops over all formfields in your DataForm to render the input form in a more dynamic way while still customizing the overall output.
In addition, FlexFormPlugin facilitates the extraction of field default values (such as valid schema options) from DataForm. See http://foswiki.org/Development/MacroForRetrievingFieldDefaultValues for background.
Parameter | Description | Default |
---|---|---|
"..." (or topic="..." | name of a topic to render the edit form for | the base topic of the current url |
revision="..." | topic revision which to use the data from while populating the edit form | |
excludeattr="..." | regular expression field attributes must match to be excluded from the output | undefined |
exclude="..." | regular expression fieldnames must match to be excluded from the output | undefined |
fields=" | list of formfields to render the interface for | all known formfields |
prefix="..." | adds a prefix string to the name while rendering the editor for a formfield | |
footer="..." | footer string to apped to the output | |
format="..." | format string to render each formfield with, more info below | $edit$mandatory |
form="..." | topic name containing the DataForm definition | form found at the base topic |
header="..." | header string to be put in front of the output | |
hidden="..." | those fields that match this regular expression will be rendered hidden | undefined |
includeattr="..." | regular expression field attributes must match to be included in the output | undefined |
include="..." | regular expression fieldnames must match to be included in the output | undefined |
mandatory="..." | string to be inserted when a field is mandatory | ** |
map=" | allows to map a fieldname to a different title string in the edit interface | original fieldnames are used as title string |
separator="..." | string to be put between each formatted output per formfield | |
sort="on/off" | sort values of multi-valued formfields | on |
valueseparator="..." | string to be put between each allowed value as defined in the form schema | , |
value="..." | value to be inserted into the edit interface; makes sense for single-field calls only | stored value in the base topic |
| these parameters allow to override the formfield properties as specified in the DataForm definition; for example a Teaser_type="text" , Teaser_size="30" will override a definition of a Teaser formfield that otherwise is a textarea of size 80x25 ; | values as defined in the DataForm definition and the current topic |
| value to be inserted into the edit interface of the named field | looks for urlparam |
| on/off/asc/desc/rev - sort allowed values before displaying them | as defined in the DataForm |
Parameter | Description | Default |
---|---|---|
"..." or topic="..." | name of a topic to display the form for | the base topic of the current url |
revision="..." | topic revision to display | |
autolink="on/off" | enable/disable WikiWord autolinking when rendering a formfield; setting autolink sets the default for all fields specific settings of = | on |
excludeattr="..." | regular expression field attributes must match to be excluded from the output | undefined |
exclude="..." | regular expression fieldnames must match to be excluded from the output | undefined |
fields=" | list of formfields to be displayed | all known formfields |
footer="..." | footer string to apped to the output | |
format="..." | format string to render each formfield with, more info below | $edit$mandatory |
form="..." | topic name containing the DataForm definition | form found at the base topic |
header="..." | header string to be put in front of the output | |
hideempty="on/off" | hide empty formfields | off |
includeattr="..." | regular expression field attributes must match to be included in the output | undefined |
include="..." | regular expression fieldnames must match to be included in the output | undefined |
labelformat="..." | format string used for labels exclusively; labels aren't real input fields; they are part of the form definition but carry read-only values only if at all | same as format |
map=" | allows to map a fieldname to a different title string (deprecated: please use | original fieldnames are used as title string |
separator="..." | string to be put between each formatted output per formfield | |
sort="on/off" | sort values of multi-valued formfields | on |
valueseparator="..." | string to be put between each allowed value as defined in the form schema | , |
| see above | defaults as defined in the DataForm definition and the current topic |
If all three format
, header
and footer
are undefined a foswikiFormSteps
block will be rendered as illustrated in the example below.
The format
parameter may contain the following pseudo-variables:
$attrs
: attribute string as given in the DataForm definition $description
: formfield description in DataForm $edit
: the HTML form element as specified by the DataForm definition, that is a input field, a textarea, a select box, whatever $extra
: the "extra" return value of the Foswiki::Form::renderForEdit()
call $mandatory
: placeholder to display the mandatory
flag when a formfield is mandatory; the format of the mandatroy flag can be defined in the mandatory
parameter to RENDERFOREDIT $name
: the original fieldname $size
: size parameter of the formfield as given in the DataForm definition $title
: the fieldtitle derived from the fieldname and remapped as specified in the map
parameter $tooltip
: formfield description in DataForm (deprecated: use $description
instead) $type
: type of formfield as given in the DataForm definition $value
: current value of the formfield; for +value
formfields this is the mapped value use $origvalue
to get the original one $origvalue
: current value of the formfield; for +value
formfields this is the original unmapped value of the formfield $values
: list of all allowed values for the formfield as defined in the DataForm definition $origvalues
: list of all allowed values; for +value
formfields this is the original unmapped value of the formfield $default
: this is the default value if no value is specified in the topic itself %RENDERFOREDIT{ form="%USERSWEB%.UserForm" topic="Sandbox.TestTopic1" exclude="Email|Comment|State" FirstName_value="Horst" LastName_value="Buchholz" map="VoIP=Skype" }%
%RENDERFORDISPLAY{ form="ValueTransactionForm" field="FromRole" format="allowed values for $title are $values, default is '$default'" }%
You do not need to install anything in the browser to use this extension. The following instructions are for the administrator who installs the extension on the server.
Open configure, and open the "Extensions" section. Use "Find More Extensions" to get a list of available extensions. Select "Install".
If you have any problems, or if the extension isn't available in configure
, then you can still install manually from the command-line. See http://foswiki.org/Support/ManuallyInstallingExtensions for more help.
Author(s): | Foswiki:MichaelDaum |
Copyright: | © 2009-2013 Michael Daum http://michaeldaumconsulting.com |
License: | GPL (Gnu General Public License) |
Release: | 13 Jul 2013 |
Version: | v2.8.0 |
Change History: | |
13 Jul 2013: | added revision parameter to access non-top revisions; improved compatibility with foswiki-1.2.x |
20 Mar 2013: | added to temporarily override the input field name |
17 Oct 2012: | rationalized include and exclude ; adding $mandatory to the default format |
24 Feb 2012: | added $origvalues to display unmapped values of +values formfields; added prefix parameter; protecting the editor of a formfield by surrounding it with tags |
25 Aug 2011: | fixed rendering +value formields yet again; added $origvalue |
18 Mar 2011: | added autolink param; fixed getting default values; added global sort param; added fieldname_format param; protecting %MACROs in value attr of an input field |
13 Aug 2010: | added fieldname_sort param to sort allowed field values before displaying them |
10 Aug 2010: | added hideempty to RENDERFORDISPLAY |
23 Jul 2010: | fixed rendering hidden fields when creating a new topic (Foswiki:Main/PasiHaekkinen) |
22 Jul 2010: | fixed not try to load a non-existing form definition; providing fallback method for retrieving default values from form definition for those formfield types that can't do that by themselves; fixed expanding field title before the formfield does; fixed expanding standard escapes at the very end of the rendering process; added better default format for RENDERFOREDIT |
07 Jun 2010: | added includeattr , excludeattr to filter formfields by their attributes |
24 Mar 2010: | fixed error where topic values were not inserted into the edit form properly |
12 Mar 2010: | cleaned up $value and $values variable in both RENDERFOREDIT and RENDERFORIDPLSAY; added $default |
11 Mar 2010: | Foswiki:Main.MartinCleaver - added ability to extract allowed values of a field Foswiki:Tasks.Item8671 |
10 Mar 2010: | added fine-grained control over each formfield, i.e. remapping of the formfield type |
08 Mar 2010: | initial release |
Dependencies: | None |
Home page: | Foswiki:Extensions/FlexFormPlugin |
Support: | Foswiki:Support/FlexFormPlugin |