From 988a31a8fc41ed1f2a99809527094885d8196594 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Tue, 15 Apr 2025 12:46:04 +0200 Subject: [PATCH] Docs: clarify 'ifnot'-behaviour in edge case, add test for this edge case --- .../ThemeConfig/Json/QuestionableTagRenderingConfigJson.ts | 3 +++ src/Models/ThemeConfig/TagRenderingConfig.ts | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson.ts b/src/Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson.ts index 65c70863cf..5d95416d10 100644 --- a/src/Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson.ts +++ b/src/Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson.ts @@ -125,6 +125,9 @@ export interface MappingConfigJson { * Note that we can not explicitly render this negative case to the user, we cannot show `does _not_ accept coins`. * If this is important to your usecase, consider using multiple radiobutton-fields without `multiAnswer` * + * Ifnot has the lowest priority in comparison with 'if', 'freeform', 'addExtraTags', ... + * In the case that two options set different values (e.g. selected option sets "X=Y" and an unselected option sets "X=" through `ifnot`), the latter ifnot is ignored. + * * ifunset: Do not apply a tag if a different mapping is chosen. */ ifnot?: TagConfigJson diff --git a/src/Models/ThemeConfig/TagRenderingConfig.ts b/src/Models/ThemeConfig/TagRenderingConfig.ts index a317007fad..6aac0d47b1 100644 --- a/src/Models/ThemeConfig/TagRenderingConfig.ts +++ b/src/Models/ThemeConfig/TagRenderingConfig.ts @@ -766,6 +766,10 @@ export default class TagRenderingConfig { * const tags = config.constructChangeSpecification("€5", undefined, undefined, {vending: "books;bicycle_tubes" charge: "€42/book"}) * tags // => [ new Tag("charge", "€5/bicycle_tube; €42/book")] * + * // Conflicting 'if' and 'ifnot' should ignore ifnot (i.e.: should not have 'fountain=' + * const config = new TagRenderingConfig({"id":"drinking_water_type", multiAnswer: true, mappings: [ {"if": "fountain=bubbler", then: "bubbler", "ifnot": "fountain="},{ "if": "fountain=tap", then: "tap", ifnot: "fountain="}, {if: "natural=spring", then: "spring", ifnot: "natural="}]}) + * const tags = config.constructChangeSpecification(undefined, undefined, [true, false, false], {}) + * tags // => [new Tag("fountain", "bubbler"), new Tag("natural", "")] * * @param freeformValue The freeform value which will be applied as 'freeform.key'. Ignored if 'freeform.key' is not set *