diff --git a/assets/layers/postoffices/postoffices.json b/assets/layers/postoffices/postoffices.json index 81d586f95..ee26dbd1f 100644 --- a/assets/layers/postoffices/postoffices.json +++ b/assets/layers/postoffices/postoffices.json @@ -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", "render": { @@ -639,4 +659,4 @@ ] } ] -} +} \ No newline at end of file diff --git a/assets/layers/public_bookcase/public_bookcase.json b/assets/layers/public_bookcase/public_bookcase.json index 4b10010cf..ef9c07710 100644 --- a/assets/layers/public_bookcase/public_bookcase.json +++ b/assets/layers/public_bookcase/public_bookcase.json @@ -399,12 +399,14 @@ "key": "brand", "type": "nsi", "helperArgs": [ - "amenity=public_bookcase", - "nobrand=" + "amenity=public_bookcase" ], "placeholder": { "en": "Name of the network" - } + }, + "addExtraTags": [ + "nobrand=" + ] }, "mappings": [ { diff --git a/src/UI/InputElement/Helpers/NameSuggestionIndexInput.svelte b/src/UI/InputElement/Helpers/NameSuggestionIndexInput.svelte index d78103976..85cc5e81b 100644 --- a/src/UI/InputElement/Helpers/NameSuggestionIndexInput.svelte +++ b/src/UI/InputElement/Helpers/NameSuggestionIndexInput.svelte @@ -23,7 +23,10 @@ let maintag = helperArgs[0].toString() 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]}` @@ -141,6 +144,32 @@ // Finally, set the extra 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) + extraTags.setData(tags) + } + } + })