Difference between revisions of "Template:FormDateField"
Jump to navigation
Jump to search
(22 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
− | + | <noinclude> | |
+ | This template is called from within Semantic Forms to display a Date field. | ||
+ | '''NOTE:''' This is a "form" template; it should NOT be called from anywhere except a semantic form. | ||
+ | |||
+ | It creates the following entry fields: | ||
+ | * <code><nowiki>{{{property|}}} Era</nowiki></code> - CE or BCE; the default is CE. | ||
+ | * <code><nowiki>{{{property|}}} Year</nowiki></code> - the year field; accepts 4 integers. | ||
+ | * <code><nowiki>{{{property|}}} Month</nowiki></code> - the month field. | ||
+ | * <code><nowiki>{{{property|}}} Day</nowiki></code> - the day field. | ||
+ | * <code><nowiki>{{{property|}}} Approximate</nowiki></code> - if day field. | ||
+ | |||
+ | '''Parameters:''' | ||
+ | * <code><nowiki>|property=</nowiki></code> - the name of the property; must be unique for the form. The template will use this value to create several fields ending with Year, Month, Day, etc. | ||
+ | * <code><nowiki>|mandatory=</nowiki></code> - if yes, then the combined field return some value. The default is no. | ||
+ | * <code><nowiki>|dataprecision=</nowiki></code> - Year, Month, or Day. Depending on this parameter, the respective fields will be made mandatory. The default is Day. | ||
+ | * <code><nowiki>|showera=</nowiki></code> - if yes, then the era will be show; if no (default), then the era field will not be shown and the value of CE will be set automatically. | ||
+ | * <code><nowiki>|showapproximate=</nowiki></code> - if yes, the approximate field will be shown; if no (default), then the approximate field will not be shown and the date will be considered not approximate (i.e. precise). | ||
+ | * <code><nowiki>|showmonthdayfields=</nowiki></code> - if yes (default), the Month and Day fields will be shown even if dataprecision=Year. If no, the Month and Day fields will only be shown if necessary. | ||
+ | * <code><nowiki>|showcaptions=</nowiki></code> - if yes (default), the captions (''Year'', ''Month'' etc.) will be shown. | ||
+ | * <code><nowiki>|adddefualt=</nowiki></code> - if yes, the date fields will have the value of ''now'' by default. If no (default), no default will be added to the fields. | ||
+ | |||
+ | </noinclude><includeonly><!-- | ||
+ | --><!-- | ||
+ | --><!-- calculate mandatory values | ||
+ | -->{{#ifeq: {{{mandatory|}}}|yes<!-- | ||
+ | --><!-- year field: mandatory | ||
+ | -->|{{#vardefine: varMandatoryYear||mandatory}}<!-- | ||
+ | --><!-- for month and day fields the mandatory values will depend on the dataprecision parameter | ||
+ | -->{{#switch: {{{dataprecision|Day}}} <!-- | ||
+ | -->|Day|Month={{#vardefine: varMandatoryMonth||mandatory}}<!-- | ||
+ | -->|#default={{#vardefine: varMandatoryMonth|}}<!-- | ||
+ | -->}}<!-- switch | ||
+ | -->{{#switch: {{{dataprecision|Day}}} <!-- | ||
+ | -->|Day={{#vardefine: varMandatoryDay||mandatory}}<!-- | ||
+ | -->|#default={{#vardefine: varMandatoryDay|}}<!-- | ||
+ | -->}}<!-- switch | ||
+ | --><!-- else: nothing is mandatory | ||
+ | -->|{{#vardefine: varMandatoryYear|}}<!-- | ||
+ | -->{{#vardefine: varMandatoryMonth|}}<!-- | ||
+ | -->{{#vardefine: varMandatoryDay|}}<!-- | ||
+ | -->}}<!-- | ||
+ | --><!-- | ||
+ | --><!-- calculate visibility for month and day fields | ||
+ | -->{{#ifeq:{{{showmonthdayfields|}}}|yes<!-- | ||
+ | --><!-- showmonthdayfields=yes: always visible | ||
+ | -->|{{#vardefine: varMonthVisible|yes}}<!-- | ||
+ | -->{{#vardefine: varDayVisible|yes}}<!-- | ||
+ | --><!-- else: depends on the dataprecision parameter | ||
+ | -->|{{#switch: {{{dataprecision|Day}}} <!-- | ||
+ | -->|Day|Month={{#vardefine: varMonthVisible|yes}}<!-- | ||
+ | -->|#default={{#vardefine: varMonthVisible|no}}<!-- | ||
+ | -->}}<!-- switch | ||
+ | -->{{#switch: {{{dataprecision|Day}}} <!-- | ||
+ | -->|Day={{#vardefine: varDayVisible|yes}}<!-- | ||
+ | -->|#default={{#vardefine: varDayVisible|no}}<!-- | ||
+ | -->}}<!-- switch | ||
+ | -->}}<!-- | ||
+ | --><!-- | ||
+ | --><!-- start displaying | ||
+ | --><!-- show era if necessary | ||
+ | --> | ||
+ | {{#ifeq:{{{showera|}}}|yes|{{#ifeq: {{{showcaptions|yes}}}|yes|''Era:'' |}}{{{field|{{{property|}}} Era|input type=dropdown|values=BCE,CE{{#ifeq:{{{adddefault|}}}|yes||default=CE|}}}}}|}} | ||
{{#if: {{#var: varMandatoryYear}}<!-- | {{#if: {{#var: varMandatoryYear}}<!-- | ||
-->|{{#vardefine: varRegexp|/^\d{4}$/}}<!-- 4 digits only | -->|{{#vardefine: varRegexp|/^\d{4}$/}}<!-- 4 digits only | ||
Line 27: | Line 88: | ||
--><!-- | --><!-- | ||
--><!-- | --><!-- | ||
− | --></includeonly> | + | --> |
+ | </includeonly> |
Latest revision as of 22:01, 1 June 2020
This template is called from within Semantic Forms to display a Date field.
NOTE: This is a "form" template; it should NOT be called from anywhere except a semantic form.
It creates the following entry fields:
{{{property|}}} Era
- CE or BCE; the default is CE.{{{property|}}} Year
- the year field; accepts 4 integers.{{{property|}}} Month
- the month field.{{{property|}}} Day
- the day field.{{{property|}}} Approximate
- if day field.
Parameters:
|property=
- the name of the property; must be unique for the form. The template will use this value to create several fields ending with Year, Month, Day, etc.|mandatory=
- if yes, then the combined field return some value. The default is no.|dataprecision=
- Year, Month, or Day. Depending on this parameter, the respective fields will be made mandatory. The default is Day.|showera=
- if yes, then the era will be show; if no (default), then the era field will not be shown and the value of CE will be set automatically.|showapproximate=
- if yes, the approximate field will be shown; if no (default), then the approximate field will not be shown and the date will be considered not approximate (i.e. precise).|showmonthdayfields=
- if yes (default), the Month and Day fields will be shown even if dataprecision=Year. If no, the Month and Day fields will only be shown if necessary.|showcaptions=
- if yes (default), the captions (Year, Month etc.) will be shown.|adddefualt=
- if yes, the date fields will have the value of now by default. If no (default), no default will be added to the fields.