diff --git a/codegen/emit_skill.py b/codegen/emit_skill.py index 4096cdd..566f854 100644 --- a/codegen/emit_skill.py +++ b/codegen/emit_skill.py @@ -262,14 +262,18 @@ def _allowlist_section(unreg: dict) -> list[str]: def _other_section(other: dict) -> list[str]: code = other.get("choiceCode", "other") + templates = other.get("relevanceTemplates", {}) + relevance = "; ".join(f"for `{t}`: `{tpl}`" for t, tpl in templates.items()) return [ "## `or_other` pattern (open \u201cOther\u201d field)\n", f"Applies to: {', '.join(f'`{t}`' for t in other.get('appliesTo', []))}. " f"Add a choice with code `{code}`, then a companion " f"row of type `{other.get('companionType', 'text')}` named " - f"`{other.get('companionSuffix', '_other')}` shown only when the " - "\u201cother\u201d choice is picked \u2014 set its `relevant` to `${} = " - f"'{code}'`. See the `select_one_other` example.\n", + f"`{other.get('companionSuffix', '_other')}` directly after the question, " + "shown only when the \u201cother\u201d choice is picked. Set its `relevant` " + f"{relevance}. A `select_multiple` value lists every ticked code, so `=` " + "would only match when \u201cother\u201d is the sole answer. See the " + "`select_one_other` and `select_multiple_other` examples.\n", ] diff --git a/registry/conventions/other.jsonld b/registry/conventions/other.jsonld index 84c970e..607925a 100644 --- a/registry/conventions/other.jsonld +++ b/registry/conventions/other.jsonld @@ -32,7 +32,10 @@ "rule": { "companionSuffix": "_other", "companionType": "text", - "relevanceTemplate": "${{${name}}} = 'other'", + "relevanceTemplates": { + "select_one": "${} = 'other'", + "select_multiple": "selected(${}, 'other')" + }, "choiceCode": "other", "appliesTo": [ "select_one", diff --git a/registry/entities/select_multiple_other/fixtures/xlsform.json b/registry/entities/select_multiple_other/fixtures/xlsform.json index b8dedaa..6460c82 100644 --- a/registry/entities/select_multiple_other/fixtures/xlsform.json +++ b/registry/entities/select_multiple_other/fixtures/xlsform.json @@ -9,7 +9,7 @@ "type": "text", "name": "geraetebesitz_other", "label": "Sonstiges (bitte angeben)", - "relevant": "${geraetebesitz} = 'other'" + "relevant": "selected(${geraetebesitz}, 'other')" } ], "choices": [ diff --git a/registry/entities/select_multiple_other/tsv.tsv b/registry/entities/select_multiple_other/tsv.tsv index 430e1ca..e580d84 100644 --- a/registry/entities/select_multiple_other/tsv.tsv +++ b/registry/entities/select_multiple_other/tsv.tsv @@ -8,4 +8,4 @@ Q M geraetebesitz 1 Welche dieser Geräte besitzen Sie? de Y 1 SQ smart Smartphone de SQ lapt Laptop de SQ tabl Tablet de -Q S geraetebesitzother geraetebesitz == 'other' Sonstiges (bitte angeben) de 1 \ No newline at end of file +Q S geraetebesitzother (geraetebesitz_other.NAOK == 'Y') Sonstiges (bitte angeben) de 1 \ No newline at end of file diff --git a/skills/cdl-survey-types/references/xlsform-syntax.md b/skills/cdl-survey-types/references/xlsform-syntax.md index 2a63e28..ddac60c 100644 --- a/skills/cdl-survey-types/references/xlsform-syntax.md +++ b/skills/cdl-survey-types/references/xlsform-syntax.md @@ -22,7 +22,7 @@ Write names and choice codes as letters and digits only (`^[a-zA-Z0-9]+$`), e.g. ## `or_other` pattern (open “Other” field) -Applies to: `select_one`, `select_multiple`. Add a choice with code `other`, then a companion row of type `text` named `_other` shown only when the “other” choice is picked — set its `relevant` to `${} = 'other'`. See the `select_one_other` example. +Applies to: `select_one`, `select_multiple`. Add a choice with code `other`, then a companion row of type `text` named `_other` directly after the question, shown only when the “other” choice is picked. Set its `relevant` for `select_one`: `${} = 'other'`; for `select_multiple`: `selected(${}, 'other')`. A `select_multiple` value lists every ticked code, so `=` would only match when “other” is the sole answer. See the `select_one_other` and `select_multiple_other` examples. ## Exclusive answers (`exclusive` column) diff --git a/src/generated/conventions.json b/src/generated/conventions.json index 9ef8283..fb8195c 100644 --- a/src/generated/conventions.json +++ b/src/generated/conventions.json @@ -143,7 +143,10 @@ "other": { "companionSuffix": "_other", "companionType": "text", - "relevanceTemplate": "${{${name}}} = 'other'", + "relevanceTemplates": { + "select_one": "${} = 'other'", + "select_multiple": "selected(${}, 'other')" + }, "choiceCode": "other", "appliesTo": [ "select_one", diff --git a/src/generated/conventions.ts b/src/generated/conventions.ts index 2d135b7..998def8 100644 --- a/src/generated/conventions.ts +++ b/src/generated/conventions.ts @@ -152,7 +152,10 @@ const conventions = { "other": { "companionSuffix": "_other", "companionType": "text", - "relevanceTemplate": "${{${name}}} = 'other'", + "relevanceTemplates": { + "select_one": "${} = 'other'", + "select_multiple": "selected(${}, 'other')" + }, "choiceCode": "other", "appliesTo": [ "select_one",