Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions codegen/emit_skill.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"`<question>{other.get('companionSuffix', '_other')}` shown only when the "
"\u201cother\u201d choice is picked \u2014 set its `relevant` to `${<question>} = "
f"'{code}'`. See the `select_one_other` example.\n",
f"`<question>{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",
]


Expand Down
5 changes: 4 additions & 1 deletion registry/conventions/other.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
"rule": {
"companionSuffix": "_other",
"companionType": "text",
"relevanceTemplate": "${{${name}}} = 'other'",
"relevanceTemplates": {
"select_one": "${<question>} = 'other'",
"select_multiple": "selected(${<question>}, 'other')"
},
"choiceCode": "other",
"appliesTo": [
"select_one",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "text",
"name": "geraetebesitz_other",
"label": "Sonstiges (bitte angeben)",
"relevant": "${geraetebesitz} = 'other'"
"relevant": "selected(${geraetebesitz}, 'other')"
}
],
"choices": [
Expand Down
2 changes: 1 addition & 1 deletion registry/entities/select_multiple_other/tsv.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Q S geraetebesitzother (geraetebesitz_other.NAOK == 'Y') Sonstiges (bitte angeben) de 1
2 changes: 1 addition & 1 deletion skills/cdl-survey-types/references/xlsform-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<question>_other` shown only when the “other” choice is picked — set its `relevant` to `${<question>} = '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 `<question>_other` directly after the question, shown only when the “other” choice is picked. Set its `relevant` for `select_one`: `${<question>} = 'other'`; for `select_multiple`: `selected(${<question>}, '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)

Expand Down
5 changes: 4 additions & 1 deletion src/generated/conventions.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@
"other": {
"companionSuffix": "_other",
"companionType": "text",
"relevanceTemplate": "${{${name}}} = 'other'",
"relevanceTemplates": {
"select_one": "${<question>} = 'other'",
"select_multiple": "selected(${<question>}, 'other')"
},
"choiceCode": "other",
"appliesTo": [
"select_one",
Expand Down
5 changes: 4 additions & 1 deletion src/generated/conventions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ const conventions = {
"other": {
"companionSuffix": "_other",
"companionType": "text",
"relevanceTemplate": "${{${name}}} = 'other'",
"relevanceTemplates": {
"select_one": "${<question>} = 'other'",
"select_multiple": "selected(${<question>}, 'other')"
},
"choiceCode": "other",
"appliesTo": [
"select_one",
Expand Down
Loading