forked from MapComplete/MapComplete
Clear extra tags in some case, automagically match input
This commit is contained in:
parent
8234616168
commit
117bf77dbd
3 changed files with 56 additions and 5 deletions
|
@ -194,6 +194,26 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "post_offic_brand",
|
||||||
|
"condition": "amenity=post_office",
|
||||||
|
"question": {
|
||||||
|
"en": "To which brand does this post office belong?"
|
||||||
|
},
|
||||||
|
"render": {
|
||||||
|
"en": "This is a {brand} post office"
|
||||||
|
},
|
||||||
|
"freeform": {
|
||||||
|
"type": "nsi",
|
||||||
|
"key": "brand",
|
||||||
|
"placeholder": {
|
||||||
|
"en": "Brand of the post office"
|
||||||
|
},
|
||||||
|
"helperArgs": [
|
||||||
|
"amenity=post_office"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "partner-brand",
|
"id": "partner-brand",
|
||||||
"render": {
|
"render": {
|
||||||
|
@ -639,4 +659,4 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -399,12 +399,14 @@
|
||||||
"key": "brand",
|
"key": "brand",
|
||||||
"type": "nsi",
|
"type": "nsi",
|
||||||
"helperArgs": [
|
"helperArgs": [
|
||||||
"amenity=public_bookcase",
|
"amenity=public_bookcase"
|
||||||
"nobrand="
|
|
||||||
],
|
],
|
||||||
"placeholder": {
|
"placeholder": {
|
||||||
"en": "Name of the network"
|
"en": "Name of the network"
|
||||||
}
|
},
|
||||||
|
"addExtraTags": [
|
||||||
|
"nobrand="
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"mappings": [
|
"mappings": [
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,10 @@
|
||||||
|
|
||||||
let maintag = helperArgs[0].toString()
|
let maintag = helperArgs[0].toString()
|
||||||
let tag = key
|
let tag = key
|
||||||
let addExtraTags = helperArgs[1].split(";")
|
let addExtraTags: string[] = []
|
||||||
|
if (helperArgs[1]) {
|
||||||
|
addExtraTags = helperArgs[1].split(";")
|
||||||
|
}
|
||||||
|
|
||||||
const path = `${tag}s/${maintag.split("=")[0]}/${maintag.split("=")[1]}`
|
const path = `${tag}s/${maintag.split("=")[0]}/${maintag.split("=")[1]}`
|
||||||
|
|
||||||
|
@ -141,6 +144,32 @@
|
||||||
// Finally, set the extra tags
|
// Finally, set the extra tags
|
||||||
extraTags.setData(tags)
|
extraTags.setData(tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value.addCallback((value) => {
|
||||||
|
// If the value changes by the user typing we might need to update the selected item or make sure we clear any old keys
|
||||||
|
|
||||||
|
// First, check if the value is already selected, in that case we don't need to do anything
|
||||||
|
if (selectedItem && selectedItem.tags[tag] === value) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the value is not selected, we check if there is an item with the same value and select it
|
||||||
|
const item = items.find((item) => item.tags[tag] === value)
|
||||||
|
if (item) {
|
||||||
|
select(item)
|
||||||
|
} else {
|
||||||
|
// If there is no item with the value, we need to clear the extra tags based on the last selected item by looping over the tags from the last selected item
|
||||||
|
if (selectedItem) {
|
||||||
|
const tags = Object.entries(selectedItem.tags).reduce((acc, [key, value]) => {
|
||||||
|
if (key !== tag && key !== maintag.split("=")[0]) {
|
||||||
|
acc[key] = ""
|
||||||
|
}
|
||||||
|
return acc
|
||||||
|
}, {} as Record<string, string>)
|
||||||
|
extraTags.setData(tags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
Loading…
Reference in a new issue