MoreFormfieldsPlugin

Additional formfield types for DataForms

Description

This plugin implements a set of additional special purpose formfields to be used in DataForm definitions.

To make use of these formfields use their type identifier in the "Type" column of a DataForm definition, such as in

Name Type Size Values Description Attributes
Attachment attachment 20      
Bytes bytes 10      
Date2 date2 30      
Datetime datetime 30      
Group group 20      
Icon icon 20      
Ipaddress ipaddress 15      
Ipv6address ipv6address 40      
Macaddress macaddress 17      
Masked masked 17      
Natedit natedit 80x25      
Multitext multitext 80      
Netmask netmask 15      
Phonenumber phonenumber 20      
Random random 20      
Select2 select2 20      
Slider slider 20      
Smartbox smartbox 5      
Time time 20      
Toggle toggle 2      
Topic topic 30      
User Or Group userorgroup 30      
User user 30      
Uuid uuid 30      
Web web 30      

When defining a formfield additional parameters may be used in the "Values" column to further customize the behavior of the element.

Known Formfield types

attachment

This formfield stores a reference to an attachment. Attachments of the current topic are selectable or any other topic attached to as specified in the topic parameter. The formfield lets you upload new attachments right from within the edit dialog.

Parameters:

  • web, topic: location where attachments are searched for, defaults to current web.topic
  • url: url for autocompletion, defaults to an internal template select2::attachment::url
  • filter: regular expression of files allowed to be uploaded (note you may use a comma instead of the pipe symbol)
  • sortable: entries in an attachment+multi formfield can be reordered using drag'n'drop if set to true
  • upload: boolean switch to enable/disable uploading an attachment, defaults to off
  • format: format string to display the attachment, expands $file, and $url to the actual attachment

autofill

A formfield that is filled automatically based on values from one or more other formfields of the same topic. During an edit-save loop, values of fields listed in the source parameter are extracted and concatenated using the specified separator. Values of an autofill formfield cannot be edited by the user.

Parameters:

Either use this approach:

  • format: specify a format string to build up the autofill formfield; use $<field-name> to reference a formfield (see example below)

… or do it the old way by looping over formfields:

  • header: add an optional string prefixed to the field value, but only when the source fields are not empty
  • fields: comma-separated list of one or more formfields to fetch values from
  • separator: separator used when concatenating all values into a new value for the autofill field
  • footer: append an optional string to the field value, but only when the source fields are not empty

A typical use-case for an autofill field is the construction of a TopicTitle based on other form properties:

Name Type Size Values Description Attributes
TopicTitle1 autofill 1 header="Project" fields="Customer, ID, Year"    
TopicTitle2 autofill 1 format="Project-$ID ($Customer, $Year)"    
Customer text 80      
ID id 4      
Year text 4      

An autofill formfield is either displayed as created by the formating rules. Or the resulting value may be displayed otherwise using a display="..." wiki app. Another more comfortable way is to cast the value into a different formfield type using the type="..." parameter. That way the computed value may be displayed using the formfield definition of the given type. The following example will query the date of the most recent comment and store it as epoch seconds in a "Last Reply" formfield. It is then displayed using the Datetime definition instead of displaying the epoch seconds as is:

Name Type Size Values Description Attributes
Last Reply autofill 1 type="datetime" format="$percntFORMATLIST{\"$percntQUERY{\"'$percntBASEWEB$percnt.$percntBASETOPIC$percnt'/META:COMMENT.date\"}$percnt\" sort=\"on\" reverse=\"on\" limit=\"1\"}$percnt" date of latest reply    

autoinc

This is a formfield type that extens Foswiki's core AUTOINC mechanism to enumerate topics when they are created and brings it to formfields. A unique number is assigned to autoinc formfields whenever a topic is created will having such a DataForm attached to it. Provisions are taken that these numbers are unique among each other. This feature allow to define number ranges based on the given configuration.

A typical use case would be to have different number ranges based on another formfield, say ProjectType:

Name Type Size Values Description Attributes
Type radio 3 new product, experimental, enhancement specifies the kind of project that is carried out M
Number autoinc 5 start="1000" query="Type='$Type'" unique project number h

Whenever a topic with such a DataForm definition is used will the Number property be calculated given the start and query parameters. That is, a unique number will be assigned for each type of project "new product", "experimental" and "enhancement". All "new product" projects receive unique numbers among each other, likewise all "experimental" projects and "enhancement" projects.

Numbering starts at the value given to the start parameter, 1000 in above example. The size column of an autoinc formfield specifies the number of digits the number should have similar to the id formfield. By default numbering starts at zero.

By default, number ranges are specified among topics using the same DataForm by means of a "base query" that filters for topics of the same kind. This list is then subdivided by the given query. If for some reason you'd like to implement number ranges among different DataForms you can disable this base query using the parameter basequery="off". Not however that you should definitely define a more elaborate query to prevent unexpected numbering among other content in the same web (see QuerySearch.)

bytes

This formfield displays a numeric value in a "humanized" bytes notation, using magnitutes of two: B, KB, MB, GB, TB, PB, EB and ZB.

Example:

Name Type Size Values Description Attributes
File Size bytes 10 max="MB" prec="4"    

The "FileSize" formfield will display the value using a maximum magnitude of megabytes using a precision of 4.

For instance a value of 2033189908 will be displayed as 1939.0010 MB given the parameters in above example definition. Without any parameters this value value would be displayed using the simples way, 1.89 GB in this case.

date2

This is an alternative for the core date formfield type using the jQuery-ui datepicker widget instead of using the Mishoo JSCalendar widget. It will launch a calendar when clicking into a date2 formfield to select a date from, as well as restricts allowed keys to be entered into the formfield. The format of a date2 formfield value will always be of a YYYY-MM-DD pattern and thus not be depending on any locale settings. This is quite important to get consistant data rather than differences based on the user's current browser language. While the value stored into a date2 formfield is locale-independent will it display according to the settings of $Foswiki::cfg{DefaultDateFormat} settings.

Example:

Date date2 40 mindate="-7d" maxdate="+7d" weekends="off"    

datetime

This formfield type combines a date2 formfield with a time formfield thus letting you pick a date time with a minute precision.

Example:

Name Type Size Values Description Attributes
Datetime datetime 10 lang="en" timezone="gmtime"    

Parameters:

  • lang: language of the input element, defaults to the current user's interface language
  • format: display format of the field, default to $Foswiki::cfg{DateManipPlugin}{DefaultDateTimeFormat} or %d %b %Y - %H:%M
  • tz, timezone: timezone defaults to the one definied in LocalSite.cfg that is gmtime or servertime

group

A group reference using JQSelect2Contrib for autocompletion.

Parameters:

  • url: url for autocompletion, default: %SCRIPTURL{"rest"}%/MoreFormfieldsPlugin/users
  • include: regular expression a group must match to be included in the selection
  • exclude: regular expression a group must not match to be included
  • sortable: entries in an group+multi formfield can be reordered using drag'n'drop if set to true

Note you may use a comma instead of the pipe symbol in regular expressions.

icon

A select box to chose an icon supported by Foswiki (famfamfam and fontawesome).

Parameters:

  • cat: list of icon categories to be included in the selection
  • include: regular expression of icons to include in the selection
  • exclude: regular expression of icons to be excluded from the selection

Note you may use a comma instead of the pipe symbol in regular expressions.

An icon category can be either a topic on the icon search path as defined in $Foswiki::cfg{JQueryPlugin}{IconSearchPath}:

  • famfamfam … to select famfamfam icons only
  • silkicons … to selec from a silk icon only,
  • flagicons … to select a flag

Or an icon category as defined in the fontawesome definition:

  • Brand Icons
  • Chart Icons
  • Currency Icons
  • Directional Icons
  • File Type Icons
  • Form Control Icons
  • Medical Icons
  • Payment Icons
  • Spinner Icons
  • Text Editor Icons
  • Video Player Icons
  • Web Application Icons

Examples:

Name Type Size Values Description Attributes Default
FamFamFamIcon icon 20 cat="famfamfam"      
SilkIcon icon 20 cat="silkicon"      
MintIcon icon 20 cat="minticons"      
FlagIcon icon 20 cat="flagicons"      
WebApp icon 20 cat="Web App"      

id

Extract the numeric identifier from the topic (or web) name. This is most usefull for topics created using the AUTOINC feature (see TemplateTopics). The AUTOINC feature adds a numeric unique identifier when the topic is created. This identifier can be extracted using an id formfield type and stored into a DataForm and be available for formatted searches.

The value in the "Size" column will be used to add leading zeros to the id. For example, given a topic FooBar1 has a DataForm

Name Type Size Values Description Attributes
ID id 4 from="topic"    

Then upon save the id formfield will have a value of 0001. There is an optional "from" parameter that may have values "topic" (default) or "web". It defines the source from which to derive the value of the id formfield.

Parameters: none

ipaddress

A general purpose IPv4 address, consisting of 4 octets, e.g. 10.0.0.1

Parameters: none

ipv6address

A general purpose IPv6 address,e.g. 2001:db8:85a3:8d3:1319:8a2e:370:7348

Parameters: none

macaddress

A hardware address given in 6 hex values, e.g. 00:1a:10:6f:ba:12

Parameters: none

masked

A normal textfield with optional masked input using JQIMaskContrib

Parameters:

  • mask: input mask
  • placeholder: placeholder character, defaults to underscore

multitext

This is a kind of text+multi formfield. it stores multiple text formfields in one.

Parameters:

  • sortable: set this to true to be able to reorder entries using drag'n'drop
  • separator: separator between individual text entries, defaults to ,. NOTE that you need to choose a separator string appropriate for the expected input. for instance, by default entries are separated by comma (,), so any string holding a comma will be separated in multiple text entries during edit. a good alternative is \n to separate strings by newline, which should be fine for a list of multiple one-line text entries.

natedit

This renders a textarea using the NatEditPlugin. The size of the imput fields is specified similar to the standard textarea formfield type.

Parameters:

* showToolbar: boolean ("true" or "false") to show/hide the edit toolbar, default "true" * autoResize: boolean switch to automatically adjust the height of the editor to fit its content, default "false" * resizable: boolean to enable/disable manual resizability of the edit area, default "false" * autoHideToolbar: boolean to enable/disable the toolbar to be displayed when the editor is focused and hidden when leaving the editor, default "false" * autoMaxExpand: boolean to automatically expand the editor to a maximum height, default "false" * minHeight: minimum height of the editor * maxHeight: maximum height of the editor

netmask

A special IP address used for routing, consisting of 4 octets, e.g. 255.255.255.0

phonenumber

A standard telephone number. This formfield uses JQueryValidate to make sure the formfield value is a valid phone number.

Parameters: none

random

This formfield type generates a random value the first time the topic is created. There are a set of different random strings:

  • alpha
  • upperalpha
  • loweralpha
  • numeric
  • alphanumeric
  • misc
  • all (alpha, numeric, misc)

Name Type Size Values Description Attributes
Random random 10 charset="alphanumeric" min="1" max="10"    

This will generate a random number of 10 characters of the given charset. If the parameters min and max are definied will the size of the value vary between the given limits.

select2

A drop-in replacement for the standard select formfield. See JQSelect2Contrib.

Parameters: none

slider

A slider widget to be used for range values. The Values column may be used to configure the element:

  • min: minimum value, defaults to 0
  • max: maximum value, defaults to 100
  • step: iterate between min and max by a specific value, defaults to 1
  • values: comma separated list of predefined values to chose among, defaults to an integer between min and max
  • range: may be "on", "off", "min" or "max" to specify the mode of the widget, if range is set to "on" two values will be configured separated by comma, defaults to "off"
  • format: format to display the range value(s); this can be any specification understood by sprintf, defaults to "%s" for single values and "%s - %s" for range values

Examples:

Name Type Size Values Description Attributes Default
Simple Slider slider 20        
Formated Slider slider 20 format="%3d%%"     20
Min slider 20 range="min"     10
Max slider 20 range="max"     10
Range slider 20 range="on"     10,90
Progress slider 20 range="min" step="5"      
Priority slider 20 none, low, medium, high, urgend, emergency     none
Priority Range slider 20 values="none, low, medium, high, urgend, emergency" range="on"     medium, high
Percent slider 20 max="1" step="0.01" format="%.2f"      

smartbox

A somewhat "smarter" checkbox formfield type. It allows to select one of the values as a placeholder representing "any" value in the selection.

So given these DataForm definitions …

Name Type Size Values Description Attributes Default
Business Area smartbox 5 Energy, Maritime, Oil & Gas, Software, All Business Areas*      
Countries smartbox 5 Europe, Austria, Belgium, Bulgaria, Croatia, Cyprus, Czechia, Denmark, Estonia, Finland, France, Germany, Greece, Hungary, Ireland, Italy, Latvia, Lithuania, Luxembourg, Malta, Netherlands, Poland, Portugal, Romania, Slovakia, Slovenia, Spain, Sweden, Europe*      

Selecting "All Business Areas" or "Europe" will select/unselect all entries at once. The "any value" selection is the one indicated by the "*" asterisk, or if not present the first in the list.

time

A time formfield using the clockpicker widget from http://weareoutman.github.io/clockpicker/

Example:

Name Type Size Values Description Attributes
Time time 10      

toggle

A toggle formfield may switch between two values, by default between "on" and "off". Alternative values may be specified like this:

Name Type Size Values Description Attributes Default
Toggle toggle 1 done      
Toggle toggle 2 on, off     off
Toggle toggle+values 2 enabled=1, disabled=0     disabled

Note that the size column has no effect.

topic

A topic reference using JQSelect2Contrib for autocompletion.

Parameters:

  • web: the web the user can choose topics from; defaults to current web
  • default: the default value to use if no value exists yet
  • url: url for autocompletion, default: %SCRIPTURL{"rest"}%/RenderPlugin/template?expand=select2::topic;contenttype=application/json
  • TopicType: name of a TopicType to be selected
  • include: regular expression topics must match to be included in the selection
  • exclude: regular expression topics must not match to be included
  • format: format string how to render a topic value while editing, defaults to $topictitle
  • sortable: entries in an topic+multi formfield can be reordered using drag'n'drop if set to true

Note you may use a comma instead of the pipe symbol in regular expressions.

Custom parameters may be added. These will be appended to the autocompletion url.

There are a couple of parameters that further customize the behavior of the select2 widget. Some of the most useful ones are:

  • minimumInputLength: number of characters that have to be entered before the autocompletion url is called to fetch matching selections from the backend; default 0
  • quietMillis: number of milliseconds to wait for input before the backend is called for autocompletion
  • limit: maximum number of values fetched from the autocompletion backend, default 10

These are also available for the user and icon formfield types.

userorgroup

This formfield type combines user and group formfields providing the same parameters.

user

A user reference using JQSelect2Contrib for autocompletion.

Parameters:

  • url: url for autocompletion, default: %SCRIPTURL{"rest"}%/MoreFormfieldsPlugin/users
  • group: members of one or more groups to select from
  • include: regular expression a user must match to be included in the selection
  • exclude: regular expression a user must not match to be included
  • sortable: entries in an user+multi formfield can be reordered using drag'n'drop if set to true

Note you may use a comma instead of the pipe symbol in regular expressions.

uuid

This formfield type generates a random UUID code the first time the topic is created.

Name Type Size Values Description Attributes
Uuid uuid 30 prefix="foobar" charset="upperalpha"    

The charset might be: upperalpha (default) or loweralpha

UUIDs have got the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX where the X chars are upper or lowercase hex values as specified by the charset parameter. An optional prefix parameter might be specified in which case the code will be <prefix>-XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX.

web

This formfield stores a reference to web.

Parameters:

  • webs: a list of webs to be displayed, "public", "user, "template", defaults to "user" to select any web except System, Trash, Applications and all template webs
  • include: regular expression webs must match to be included in the selection
  • exclude: regular expression webs must match to be excluded; exclude has got higher precedence than the webs parameter if specified.
  • url: url for autocompletion, defaults to an internal template select2::wweb::url
  • sortable: entries in an web+multi formfield can be reordered using drag'n'drop if set to true

Installation Instructions

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. "Extensions Operation and Maintenance" Tab → "Install, Update or Remove extensions" Tab. Click the "Search for Extensions" button. Enter part of the extension name or description and press search. Select the desired extension(s) and click install. If an extension is already installed, it will not show up in the search results.

You can also install from the shell by running the extension installer as the web server user: (Be sure to run as the webserver user, not as root!)
cd /path/to/foswiki
perl tools/extension_installer <NameOfExtension> 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 https://foswiki.org/Support/ManuallyInstallingExtensions for more help.

Dependencies

NameVersionDescription
Foswiki::Plugins::DBCachePlugin>=9.00Required
Foswiki::Plugins::JQueryPlugin>=9.00Required
Foswiki::Plugins::RenderPlugin>=4.00Required
Foswiki::Plugins::TopicInteractionPlugin>=6.00Required
Foswiki::Plugins::ImagePlugin>=8.00Required
Foswiki::Contrib::JQSelect2Contrib>1.00Required
Foswiki::Contrib::JQIMaskContrib>0Required
JSON>=2.59Required
Scalar::Util>=0Required
Foswiki::Plugins::TopicTitlePlugin>1.00Required for Foswiki < 2.2

Change History

29 Apr 2024: allow regexes to be comma separated in formfield definitions
19 Mar 2024: added format parameter to attachment field
04 Dec 2023: added upload parameter to attachment field
30 Nov 2023: added weekend parameter to date2 and datetime fields
11 Oct 2023: added masked input to time and datetime fields; added new formfield type masked for masked text input
29 Aug 2023: added mindate and maxdate to date2 and datetime formfields
21 Jul 2023: new formfield uuid
21 Oct 2022: attachment+multi formfields now allow to upload multiple files at once
05 May 2022: new major release
17 Dec 2021: added from parameter to id formfield
02 Nov 2021: new formfield random
03 Mar 2021: new formfield toggle
13 Oct 2020: new parameter format for topic fields
08 May 2020: new formfield slider
22 Aug 2019: new formfield multitext
10 Jan 2019: new formfields group and userorgroup; added include and exclude params to topic formfield; added group, include and exclude params to user formfield; multiple improvements to date2 formfield, i.e. convert format strings to jQuery ui; using core's datetime parser now instead of a local one, which in turn brings in DateManipPlugin's capabilities if installed; make use of JQueryPlugin's new icon service for the icon formfield; added protocol param to phonenumber formfield which was hard-coded to sip before; added saveMetaDataHandler integrating into MetaDataPlugin
23 Nov 2018: added new formfields group and userorgroup
28 May 2018: new formfields bytes and autoinc
12 Jan 2018: fixed thumbnails in topic, user and attachment formfields
13 Sep 2017: added attachment formfield
27 Jan 2017: render empty date2 formfields as an empty string, not 01 Jan 1970
25 Jan 2017: fixed topic formfield to properly store web dot topic values
16 Jan 2017: replace MoreFormfieldsAjaxHelper with a template solution to be able to override it when required; fixes in id and autofill formfields; defaulting to YYYY/MM/DD in date2 formfield now to prevent browsers from interpreting date formfields using their own idea of locales; added an afterSaveHandler for formfield classes; add register of latest fontawesome icons for the icon formfield
29 Jun 2016: replaced MoreformfieldAjaxHelper topic with a template approach for higher flexibility
31 May 2016: added formfield types date2, ipv6address and natedit; removed dependency on YAML; added a format parameter to the autofill formfield type; added beforeSaveHandlers to network address formfield types to normalize their store format on save
01 Mar 2016: fixed select2 in jquery-ui modal not allowing focus
09 Jan 2016: added ipv6, fixed validation of all network addresses by properly integrating it into jquery.validate
09 Apr 2015: documentation; final bugfixing before release; updated to latest clockpicker
26 Mar 2015: updated list of all fontawesom icons; fixed rendering of Topic formfields values
16 Dec 2014: fixed thumbnails in user autocompletion; don't inherit from ListFieldDefinition for performance reasons
22 Aug 2014: added smarbox formfield
04 Apr 2014: fixed compatibility with foswiki >= 1.2.0
23 Sep 2010: initial release

PackageForm edit

Author Michael Daum
Version 11.30
Release 29 Apr 2024
Description Additional formfield types for DataForms
Repository https://github.com/foswiki/MoreFormfieldsPlugin
Copyright © 2010-2024 Michael Daum
License GPL (Gnu General Public License)
Home Foswiki:Extensions/MoreFormfieldsPlugin
Support Foswiki:Support/MoreFormfieldsPlugin
Topic revision: r1 - 19 Mar 2024, ProjectContributor - This page was cached on 19 Oct 2024 - 13:30.

This site is powered by FoswikiCopyright © by the contributing authors. All material on this site is the property of the contributing authors.
Ideas, requests, problems regarding Irish Doughnut Economics Network? Send feedback