Documentation
MasterForm web
Masterform Web makes it possible to easily distribute the form for autocompletion of addresses.
Basic application
Import of css and js:
<link rel="stylesheet" href="https://api.masterform.cz/bundle/v1/masterform-style.css">
<script type="text/javascript" src="https://api.masterform.cz/bundle/v1/masterform.js"></script>
Defining of form-like elements, that we want to use for autocompletion:
const placeEl = document.getElementById('place')
const cityEl = document.getElementById('city')
const postCodeEl = document.getElementById('postCode')
Initialization of MasterForm:
const masterForm = MasterForm.init('webKey')
webKey is accessible in our administration.
Setting of the autocompletion:
// Autocompletion of places of address
masterForm.place({
'place': placeEl,
'city': cityEl,
'postCode': postCodeEl,
'countryCode': 'de'
})
// Autocompletion of municipalities
masterForm.city({
'city': cityEl,
'countryCode': 'de'
})
With all objects, it is possible to set up countryCode as a form-like element. MasterForm will be automatically detect the country chosen by the user :
masterForm.place({
'place': placeEl,
'city': cityEl,
'postCode': postCodeEl,
'countryCode': document.getElementById('countryCode')
})
Further possibilities
Přenastavení již inicializovaného objektu:
// Standard initialisation
masterForm.place({
'place': placeEl,
'city': cityEl,
'postCode': postCodeEl,
'countryCode': 'de'
})
// Adjustment of the setting
document.querySelector('.some-element').addEventListener('click', function (e) {
masterForm.setSettings({
'countryCode': 'fr'
})
})
Callback function
const masterForm = MasterForm.init('webKey', {
// Item in the autocompletion
'onValueItem': function (data) {
return '<div class="custom-output">' + data.suggestionValue + '</div>'
},
// After the chosen item in the autocompletion
'onCompletedSelectedItem': function (data) {
console.log(data)
}
})
Design of the autocompletion
Setting of the design:
const masterForm = init('webKey', {
'theme': 'default' // default, classic, modern
})
Individually for separate objects:
masterForm.place({
'theme': 'modern'
...
})
Individual design of the autocompletion
Definition of an individual class
const masterForm = init('webKey', {
'theme': 'custom-theme'
})
.masterform-v1 .custom-theme {}
MasterForm API
Each demand is called upon by means of POST methods, it includes API key (you will find it in administration) and it includes JSON string in the body.
API Endpoints
Url api: https://api.masterform.cz
Available endpoints:
- /v1/autocomplete/place (autocompletion of places )
- /v1/autocomplete/city (autocompletion of municipalities)
Autocompletion of places of address
Requirement
JSON parameters
Title | Type | Default value | Mandatory | Description |
---|---|---|---|---|
query.place |
string | Yes | Name of the place of address | |
query.city |
string | No | City name. If it is filled out, places of address will be limited to this merit. | |
query.postCode |
string | No | Zip code. If it is filled out, places of address or cities will be limited to this merit. | |
query.countryCode |
string |
de
|
No | Country code. Limits the search results to the chosen country. |
limit |
int |
10
|
No | Number of items in the search results. Maximum number is 50. |
Answer
{
"status": "success",
"code": 200,
"items": [
{
"type": "place",
"isCompleted": false,
"suggestionValue": "Küfnersgewend",
"values": {
"countryCode": "de"
}
},
{
"type": "place",
"isCompleted": false,
"suggestionValue": "Küfnerstraße",
"values": {
"countryCode": "de"
}
},
{
"type": "place",
"isCompleted": true,
"suggestionValue": "Küfnersgewend 4, 95463 Bindlach",
"values": {
"number": "4",
"street": "Küfnersgewend",
"locality": "",
"city": "Bindlach",
"district": "Landkreis Bayreuth",
"region": "Bayern",
"postCode": "95463",
"placeAndNumber": "Küfnersgewend 4",
"address": "Küfnersgewend 4, 95463 Bindlach",
"id": "PdrWJIwBx9OKiBfac9wo",
"countryCode": "de"
}
},
{
"type": "place",
"isCompleted": true,
"suggestionValue": "Küfnerstraße 10, 81927 München",
"values": {
"number": "10",
"street": "Küfnerstraße",
"locality": "",
"city": "München",
"district": "",
"region": "Bayern",
"postCode": "81927",
"placeAndNumber": "Küfnerstraße 10",
"address": "Küfnerstraße 10, 81927 München",
"id": "LenYJIwBx9OKiBfaMWbL",
"countryCode": "de"
}
},
{
"type": "place",
"isCompleted": true,
"suggestionValue": "Küfnersgewend 2, 95463 Bindlach",
"values": {
"number": "2",
"street": "Küfnersgewend",
"locality": "",
"city": "Bindlach",
"district": "Landkreis Bayreuth",
"region": "Bayern",
"postCode": "95463",
"placeAndNumber": "Küfnersgewend 2",
"address": "Küfnersgewend 2, 95463 Bindlach",
"id": "R9rWJIwBx9OKiBfac9wo",
"countryCode": "de"
}
},
{
"type": "place",
"isCompleted": true,
"suggestionValue": "Küfnersgewend 6a, 95463 Bindlach",
"values": {
"number": "6a",
"street": "Küfnersgewend",
"locality": "",
"city": "Bindlach",
"district": "Landkreis Bayreuth",
"region": "Bayern",
"postCode": "95463",
"placeAndNumber": "Küfnersgewend 6a",
"address": "Küfnersgewend 6a, 95463 Bindlach",
"id": "StrWJIwBx9OKiBfac9wo",
"countryCode": "de"
}
},
{
"type": "place",
"isCompleted": true,
"suggestionValue": "Küfnersgewend 6b, 95463 Bindlach",
"values": {
"number": "6b",
"street": "Küfnersgewend",
"locality": "",
"city": "Bindlach",
"district": "Landkreis Bayreuth",
"region": "Bayern",
"postCode": "95463",
"placeAndNumber": "Küfnersgewend 6b",
"address": "Küfnersgewend 6b, 95463 Bindlach",
"id": "D9vWJIwBx9OKiBfadxyx",
"countryCode": "de"
}
},
{
"type": "place",
"isCompleted": true,
"suggestionValue": "Küfnersgewend 8, 95463 Bindlach",
"values": {
"number": "8",
"street": "Küfnersgewend",
"locality": "",
"city": "Bindlach",
"district": "Landkreis Bayreuth",
"region": "Bayern",
"postCode": "95463",
"placeAndNumber": "Küfnersgewend 8",
"address": "Küfnersgewend 8, 95463 Bindlach",
"id": "EtvWJIwBx9OKiBfadxyx",
"countryCode": "de"
}
}
]
}
Autocompletion of municipalities
Requirement
JSON parameters
Title | Type | Default value | Mandatory | Description |
---|---|---|---|---|
query.city |
string | Yes | Name of the municipality | |
query.countryCode |
string |
de
|
No | Country code. Limits the search results to the chosen country. |
limit |
int |
10
|
No | Number of items in the search results. Maximum number is 50. |
Answer
{
"status": "success",
"code": 200,
"items": [
{
"type": "city",
"isCompleted": true,
"suggestionValue": "München",
"values": {
"countryCode": "de",
"city": "München",
"id": "d-TXJIwBx9OKiBfasvaY"
}
},
{
"type": "city",
"isCompleted": true,
"suggestionValue": "Münster",
"values": {
"countryCode": "de",
"city": "Münster",
"id": "_oDOJIwBx9OKiBfai5FQ"
}
},
{
"type": "city",
"isCompleted": true,
"suggestionValue": "Bad Münstereifel",
"values": {
"countryCode": "de",
"city": "Bad Münstereifel",
"id": "Ip3QJIwBx9OKiBfamxMa"
}
},
{
"type": "city",
"isCompleted": true,
"suggestionValue": "Münsingen",
"values": {
"countryCode": "de",
"city": "Münsingen",
"id": "5bDSJIwBx9OKiBfaQ_TG"
}
},
{
"type": "city",
"isCompleted": true,
"suggestionValue": "Korntal-Münchingen",
"values": {
"countryCode": "de",
"city": "Korntal-Münchingen",
"id": "C7rTJIwBx9OKiBfaDilw"
}
},
{
"type": "city",
"isCompleted": true,
"suggestionValue": "Grafing bei München",
"values": {
"countryCode": "de",
"city": "Grafing bei München",
"id": "B-rYJIwBx9OKiBfaW9y9"
}
},
{
"type": "city",
"isCompleted": true,
"suggestionValue": "Bad Münder am Deister",
"values": {
"countryCode": "de",
"city": "Bad Münder am Deister",
"id": "0DHiJIwBx9OKiBfacE1N"
}
},
{
"type": "city",
"isCompleted": true,
"suggestionValue": "Münster (Hessen)",
"values": {
"countryCode": "de",
"city": "Münster (Hessen)",
"id": "78zVJIwBx9OKiBfaB_Ge"
}
},
{
"type": "city",
"isCompleted": true,
"suggestionValue": "Garching bei München",
"values": {
"countryCode": "de",
"city": "Garching bei München",
"id": "VefXJIwBx9OKiBfa8l45"
}
},
{
"type": "city",
"isCompleted": true,
"suggestionValue": "Müncheberg",
"values": {
"countryCode": "de",
"city": "Müncheberg",
"id": "YFzqJIwBx9OKiBfaAUMK"
}
}
]
}