MapComplete/Docs/SpecialInputElements.md

7.3 KiB

Available types for text fields

The listed types here trigger a special input element. Use them in tagrendering.freeform.type of your tagrendering to activate them

Table of contents

  1. string
  2. float
  3. pfloat
  4. text
  5. nat
  6. pnat
  7. int
  8. date
  9. time
  10. color
  11. direction
  12. Input helper
  1. key
  2. icon
  3. velopark
  4. id
  5. regex
  6. simple_tag
  7. translation
  8. tag
  9. nsi

string

A simple piece of text which is at most 255 characters long

float

A decimal number

pfloat

A positive decimal number or zero

text

A longer piece of text. Uses an textArea instead of a textField

nat

A whole, positive number or zero

pnat

A strict positive number

int

A whole number, either positive, negative or zero

date

A date with date picker

time

A time picker

color

Shows a color picker

direction

A geographical direction, in degrees. 0° is north, 90° is east, ... Will return a value between 0 (incl) and 360 (excl).

Input helper

This element has an input helper showing a map and 'viewport' indicating the direction. By default, this map is zoomed to zoomlevel 17, but this can be changed with the first argument

distance

A geographical distance in meters (rounded at two points). Will give an extra minimap with a measurement tool. Arguments: [ zoomlevel, preferredBackgroundMapType (comma separated) ], e.g. `["21", "map,photo"]

slope

Validates that the slope is a valid number.The accompanying input element uses the gyroscope and the compass to determine the correct incline. The sign of the incline will be set automatically. The bearing of the way is compared to the bearing of the compass, as such, the device knows if it is measuring in the forward or backward direction.

url

The validatedTextField will format URLs to always be valid and have a https://-header (even though the 'https'-part will be hidden from the user. Furthermore, some tracking parameters will be removed

email

An email adress

phone

A phone number

fediverse

Validates fediverse addresses and normalizes them into @username@server-format

image

Same as the URL-parameter, except that it checks that the URL ends with .jpg, .png or some other typical image format

opening_hours

Has extra elements to easily input when a POI is opened.

Helper arguments

Only one helper argument named options can be provided. It is a JSON-object of type { prefix: string, postfix: string }:

subarg doc
prefix Piece of text that will always be added to the front of the generated opening hours. If the OSM-data does not start with this, it will fail to parse.
postfix Piece of text that will always be added to the end of the generated opening hours

Example usage

To add a conditional (based on time) access restriction:


"freeform": {
    "key": "access:conditional",
    "type": "opening_hours",
    "helperArgs": [
        {
          "prefix":"no @ (",
          "postfix":")"
        }
    ]
}

Don't forget to pass the prefix and postfix in the rendering as well: {opening_hours_table(opening_hours,yes @ &LPARENS, &RPARENS )

points_in_time

'Points in time' are points according to a fixed schedule, e.g. 'every monday at 10:00'. They are typically used for postbox collection times or times of mass at a place of worship

currency

Validates monetary amounts

wikidata

A wikidata identifier, e.g. Q42.

Helper arguments

name doc
key the value of this tag will initialize search (default: name). This can be a ';'-separated list in which case every key will be inspected. The non-null value will be used as search
options A JSON-object of type { removePrefixes: Record<string, string[]>, removePostfixes: Record<string, string[]>, ... }. See the more detailed explanation below
Suboptions
subarg doc
removePrefixes remove these snippets of text from the start of the passed string to search. This is either a list OR a hash of languages to a list. The individual strings are interpreted as case ignoring regexes
removePostfixes remove these snippets of text from the end of the passed string to search. This is either a list OR a hash of languages to a list. The individual strings are interpreted as case ignoring regexes.
instanceOf A list of Q-identifier which indicates that the search results must be an entity of this type, e.g. Q5 for humans
notInstanceof A list of Q-identifiers which indicates that the search results must not be an entity of this type, e.g. Q79007 to filter away all streets from the search results
multiple If 'yes' or 'true', will allow to select multiple values at once

Example usage

The following is the 'freeform'-part of a layer config which will trigger a search for the wikidata item corresponding with the name of the selected feature. It will also remove '-street', '-square', ... if found at the end of the name

"freeform": {
    "key": "name:etymology:wikidata",
    "type": "wikidata",
    "helperArgs": [
        "name",
        {
            "removePostfixes": {"en": [
                "street",
                "boulevard",
                "path",
                "square",
                "plaza",
            ],
             "nl": ["straat","plein","pad","weg",laan"],
             "fr":["route (de|de la|de l'| de le)"]
             },

            "#": "Remove streets and parks from the search results:"
             "notInstanceOf": ["Q79007","Q22698"]
        }

    ]
}

Another example is to search for species and trees:

 "freeform": {
        "key": "species:wikidata",
        "type": "wikidata",
        "helperArgs": [
          "species",
          {
          "instanceOf": [10884, 16521]
        }]
      }

key

Validates a key, mostly that no weird characters are used

icon

Makes sure that a valid .svg-path is added

velopark

A special URL-validator that checks the domain name and rewrites to the correct velopark format.

id

Checks for valid identifiers for layers, will automatically replace spaces and uppercase

regex

Only used when your input should be a valid regex. This validator is only used as helper for Studio and should not be used in a mapcomplete-theme.

simple_tag

A simple tag of the format key=value where key conforms to a normal key `

translation

Makes sure the the string is of format Record<string, string>

tag

A simple tag of the format key=value OR a tagExpression

nsi

Gives a list of possible suggestions for a brand or operator tag. Note: this is detected automatically; there is no need to explicitly set this

This document is autogenerated from src/UI/InputElement/Validators.ts