Extension:AutoFillFormField

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.svg
AutoFillFormField

Release status:Extension status beta

ImplementationTemplate:Extension#type Parser function
DescriptionTemplate:Extension#description Allows to automatically fill form input fields based on the (live) input of other fields
Author(s)Template:Extension#username Simon Heimler (Fannontalk)
Latest versionTemplate:Extension#version 0.2.0 (April 2015)
MediaWikiTemplate:Extension#mediawiki 1.19+
PHPTemplate:Extension#php 5.2+
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license MIT License
Download
README
Hooks usedTemplate:Extension#hook
BeforePageDisplayManual:Hooks/BeforePageDisplay

Translate the AutoFillFormField extension if it is available at translatewiki.net

Check usage and version matrix.

The AutoFillFormField extension allows to automatically fill form input fields provided by the Semantic Forms extension based on the (live) input of other fields.

Rationale[edit]

In some situations, choosing the correct page name is difficult, since there are many possibilities how to do it. This leads to inconsistencies, duplicated pages etc. This extension is an attempt to solve this problem when using Semantic Forms in edit mode.

It allows to define a field that holds the final page URL, providing a pattern how to build it. This pattern can create references to other fields, whose in-put values will be incorporated while typing. 

Installation[edit]

This extension requires Semantic MediaWiki and Semantic Forms to be installed first.


  • Download and place the file(s) in a directory called AutoFillFormField in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    require_once "$IP/extensions/AutoFillFormField/AutoFillFormField.php";
    
  • YesY Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.


Instead of downloading the tarball you may also check this extension out via Git:

git clone https://github.com/Fannon/AutoFillFormField.git

Usage[edit]

AutoFillFormField is triggered by applying certain CSS classes to fields in your Semantic Form.

Target Field[edit]

First you have to define the target field by applying the AutoFillFormFieldTarget class to it. The field also needs to declare how the URL / name is built. This is done by adding a second class starting with URL: followed by a string that declares how the field value needs to be built.

This string supports variables and substitutions. Variables are encapsulated in ? signs, like ?variable?.

Currently the following substitutions are supported:

  • ___ to (space). This is important because you can't add spaces to a classname.
  • FULLPAGENAME will be substituted by the current full pagename.

Examples:

  • |class=AutoFillFormFieldTarget URL:?strasse?,___?plz?___?ort?
  • |class=AutoFillFormFieldTarget URL:FULLPAGENAME/?ip?

Source Fields[edit]

A source field is defined by adding the class AutoFillFormFieldSource and the variablename prefixed by source_. Example: source_country.

Every field that is referenced by a ?variable? needs a corresponding source_target.

Complete Example[edit]

Semantic Form Markup[edit]

The important parts are marked in bold.

{{{for template|HeimarbeitsplatzAdresse|heimarbeitsplatz|label=heimarbeitsplatz|multiple|minimum instances=0}}}
  {| class="formtable"
  ! Heimarbeitsplatz:
  | {{{field|heimarbeitsplatz|size=none|class=AutoFillFormFieldTarget URL:?strasse?,___?plz?___?ort?|input type=text|list|delimiter=;|default=}}}
  |-
  ! Straße:
  | {{{field|strasse|size=none|class=AutoFillFormFieldSource source_strasse|input type=text|mandatory}}}
  |-
  ! Postleitzahl:
  | {{{field|plz|size=none|class=AutoFillFormFieldSource source_plz|input type=text|mandatory}}}
  |-
  ! Ort:
  | {{{field|ort|size=none|class=AutoFillFormFieldSource source_ort|input type=text|mandatory}}}
  |-
  ! Land:
  | {{{field|land|size=none|class=AutoFillFormFieldSource source_land|input type=dropdown|mandatory|default=DE|values from namespace=Land|existing values only}}}
  |-
  |}
  {{{end template}}}

Result[edit]

This is how the code above will look look / behave:

AutoFillFormField-Exampe.gif