diff --git a/codegen/emit_ts.py b/codegen/emit_ts.py index 251fbd9..117a512 100644 --- a/codegen/emit_ts.py +++ b/codegen/emit_ts.py @@ -262,8 +262,14 @@ def generate_appearances(registry: dict[str, Any], output: Path): " /**", " * LimeSurvey question theme the appearance selects: `name` goes to the Q row's", " * `question_theme_name`, each of `attributes` to a column of its own.", + " * `emitOnlyAttributes` are written the same way but do not identify the", + " * appearance on the way back (presentation only).", " */", - " lsQuestionTheme?: { name: string; attributes?: Record };", + " lsQuestionTheme?: {", + " name: string;", + " attributes?: Record;", + " emitOnlyAttributes?: Record;", + " };", "}", "", "export const APPEARANCES: Record = {", diff --git a/registry/root.jsonld b/registry/root.jsonld index f40b426..a31bb30 100644 --- a/registry/root.jsonld +++ b/registry/root.jsonld @@ -143,6 +143,9 @@ "name": "bootstrap_dropdown", "attributes": { "show_search": "true" + }, + "emitOnlyAttributes": { + "width_entry": "true" } } }, diff --git a/registry/schema.jsonld b/registry/schema.jsonld index 6ab96e5..bff4c62 100644 --- a/registry/schema.jsonld +++ b/registry/schema.jsonld @@ -905,7 +905,7 @@ "consumedBy": [ "ls-transformer" ], - "description": "`{name, attributes?}`: the LimeSurvey question theme this appearance selects, written to the Q row as `question_theme_name` = `name`, plus each of `attributes` (theme attribute → value) as a column of its own; LimeSurvey's TSV import sets the theme from `question_theme_name` and stores the other columns as question attributes. Applies where `validForTypes` allows, together with `lsTypeOverride` if any (autocomplete: `!` + bootstrap_dropdown + show_search=true). The way back writes this appearance for a Q row whose `question_theme_name` and attributes match (and whose type is `lsTypeOverride`, when set); a row with the override but not the theme reads back as the appearance that has the override and no theme (minimal)." + "description": "`{name, attributes?, emitOnlyAttributes?}`: the LimeSurvey question theme this appearance selects, written to the Q row as `question_theme_name` = `name`, plus each of `attributes` (theme attribute → value) as a column of its own; LimeSurvey's TSV import sets the theme from `question_theme_name` and stores the other columns as question attributes. Applies where `validForTypes` allows, together with `lsTypeOverride` if any (autocomplete: `!` + bootstrap_dropdown + show_search=true). `emitOnlyAttributes` are written like `attributes` but are presentational: the way back ignores them, so a TSV without them (made by an earlier version) still reads back as this appearance (autocomplete: width_entry=true, so the closed dropdown is as wide as the selected entry, not the longest option). The way back writes this appearance for a Q row whose `question_theme_name` and `attributes` match (and whose type is `lsTypeOverride`, when set); a row with the override but not the theme reads back as the appearance that has the override and no theme (minimal)." } } }, diff --git a/src/conventions/questionTheme.ts b/src/conventions/questionTheme.ts index f53d14b..ecce710 100644 --- a/src/conventions/questionTheme.ts +++ b/src/conventions/questionTheme.ts @@ -2,8 +2,10 @@ * An appearance can select a LimeSurvey question theme (registry Appearance * `lsQuestionTheme`): `name` goes to the Q row's `question_theme_name`, each * theme attribute to a column of its own. `autocomplete` → `!` + - * `bootstrap_dropdown` + `show_search=true`, LimeSurvey's searchable dropdown - * (#226). LimeSurvey's TSV import sets the theme from `question_theme_name` + * `bootstrap_dropdown` + `show_search=true` (+ `width_entry=true`), LimeSurvey's + * searchable dropdown (#226). Only `attributes` identify the appearance on the + * way back; `emitOnlyAttributes` (`width_entry`) are presentation, so TSVs + * from before they were emitted still read back. LimeSurvey's TSV import sets the theme from `question_theme_name` * and stores the other columns as question attributes. */ import { APPEARANCES } from '../generated/Appearances.js'; diff --git a/src/generated/Appearances.ts b/src/generated/Appearances.ts index e110c79..09746bf 100644 --- a/src/generated/Appearances.ts +++ b/src/generated/Appearances.ts @@ -15,8 +15,14 @@ export interface AppearanceSpec { /** * LimeSurvey question theme the appearance selects: `name` goes to the Q row's * `question_theme_name`, each of `attributes` to a column of its own. + * `emitOnlyAttributes` are written the same way but do not identify the + * appearance on the way back (presentation only). */ - lsQuestionTheme?: { name: string; attributes?: Record }; + lsQuestionTheme?: { + name: string; + attributes?: Record; + emitOnlyAttributes?: Record; + }; } export const APPEARANCES: Record = { @@ -33,7 +39,7 @@ export const APPEARANCES: Record = { validForTypes: ["select_one", "select_one_from_file"], lsEffect: "Override LS type from L to ! with LimeSurvey's core question theme bootstrap_dropdown and its show_search attribute: a dropdown the respondent can search by typing", lsTypeOverride: "!", - lsQuestionTheme: {"name": "bootstrap_dropdown", "attributes": {"show_search": "true"}}, + lsQuestionTheme: {"name": "bootstrap_dropdown", "attributes": {"show_search": "true"}, "emitOnlyAttributes": {"width_entry": "true"}}, }, "horizontal": { supported: true, diff --git a/src/lstsv/columns.ts b/src/lstsv/columns.ts index d598181..99b43ad 100644 --- a/src/lstsv/columns.ts +++ b/src/lstsv/columns.ts @@ -53,10 +53,11 @@ export const BASE_COLUMNS = [ * - `other_replace_text`: the label of the native "other" answer's text box, * carrying the XLSForm `_other` companion's label (convention:other). * - * - `question_theme_name`, `show_search`: the LimeSurvey question theme an + * - `question_theme_name`, `show_search`, `width_entry`: the LimeSurvey question theme an * appearance selects and that theme's attributes (registry * `lsQuestionTheme`): `autocomplete` → `bootstrap_dropdown` with - * `show_search=true`, a searchable dropdown. LimeSurvey's import sets the + * `show_search=true`, a searchable dropdown whose closed width follows the + * selected entry (`width_entry=true`), not the longest option. LimeSurvey's import sets the * theme from `question_theme_name` and stores the other columns as * question attributes. * @@ -81,6 +82,7 @@ export const ATTRIBUTE_COLUMNS = [ 'other_replace_text', 'question_theme_name', 'show_search', + 'width_entry', ] as const; export type BaseColumn = (typeof BASE_COLUMNS)[number]; diff --git a/src/pipelines/lstsv2xlsform/README.md b/src/pipelines/lstsv2xlsform/README.md index 5fb2d19..7835209 100644 --- a/src/pipelines/lstsv2xlsform/README.md +++ b/src/pipelines/lstsv2xlsform/README.md @@ -42,7 +42,7 @@ CLI: `formtransform lstsv2xlsform `. | `cssclass=cdlvocab-` | `select_*_from_file .csv`, inlined A rows dropped | shares `vocabFromCssClass` with the DDI path | | `mandatory=Y` / `default` | `required: yes` / `default` | direct | | type override `!` / `T` | `appearance: minimal` / `multiline` | inverts `APPEARANCES[*].lsTypeOverride` — registry-driven, not hardcoded | -| `question_theme_name` (+ theme attributes) | the appearance whose `lsQuestionTheme` matches: `!` + `bootstrap_dropdown` + `show_search=true` → `autocomplete` | inverts `APPEARANCES[*].lsQuestionTheme`; `bootstrap_dropdown` without `show_search=true` stays `minimal` | +| `question_theme_name` (+ theme attributes) | the appearance whose `lsQuestionTheme` matches: `!` + `bootstrap_dropdown` + `show_search=true` → `autocomplete` | inverts `APPEARANCES[*].lsQuestionTheme`; `bootstrap_dropdown` without `show_search=true` stays `minimal`; `emitOnlyAttributes` (`width_entry`) are not checked | | F + SQ + A | `begin_group appearance=table-list` + child `select_one`s | inverts the grid → F encoding | | SL welcome/end text | `note` named `welcome` / `end` | inverts note promotion | | per-language rows | `label::` / `hint::` | direct | diff --git a/src/pipelines/xlsform2lstsv/appearanceHandler.ts b/src/pipelines/xlsform2lstsv/appearanceHandler.ts index 85e0061..f8965a7 100644 --- a/src/pipelines/xlsform2lstsv/appearanceHandler.ts +++ b/src/pipelines/xlsform2lstsv/appearanceHandler.ts @@ -65,6 +65,7 @@ export class AppearanceHandler { columns = { [QUESTION_THEME_COLUMN]: theme.name, ...(theme.attributes ?? {}), + ...(theme.emitOnlyAttributes ?? {}), }; } return columns; diff --git a/tests/live/limesurvey/test_lstsv_attributes.py b/tests/live/limesurvey/test_lstsv_attributes.py index b544386..02d00ae 100644 --- a/tests/live/limesurvey/test_lstsv_attributes.py +++ b/tests/live/limesurvey/test_lstsv_attributes.py @@ -138,6 +138,7 @@ def test_long_file_list_dropdown_with_derived_codes(limesurvey_client: Client, t props = limesurvey_client.get_question_properties(q["qid"], settings=["question_theme_name"]) assert props.get("question_theme_name") == "bootstrap_dropdown", props assert _attributes(limesurvey_client, q["qid"]).get("show_search") == "true" + assert _attributes(limesurvey_client, q["qid"]).get("width_entry") == "true" options = limesurvey_client.get_question_properties(q["qid"], settings=["answeroptions"])["answeroptions"] # Every derived code arrived unchanged (LimeSurvey stores varchar(5)), # and the mapping gives each one its file code back. diff --git a/tests/ts/unit/questionTheme.test.ts b/tests/ts/unit/questionTheme.test.ts index cdc6eb7..1b2c53a 100644 --- a/tests/ts/unit/questionTheme.test.ts +++ b/tests/ts/unit/questionTheme.test.ts @@ -65,6 +65,7 @@ describe('appearance → LimeSurvey question theme (#226)', () => { expect(q['type/scale']).toBe('!'); expect(q.question_theme_name).toBe('bootstrap_dropdown'); expect(q.show_search).toBe('true'); + expect(q.width_entry).toBe('true'); }, ); @@ -139,6 +140,16 @@ describe('LimeSurvey question theme → appearance (#226)', () => { expect(out.survey[0]).toMatchObject({ appearance: 'minimal' }); }); + test('a 0.11.0 TSV without width_entry still reads back as autocomplete', async () => { + const tsv = withCell( + await toTsv('select_one land', 'autocomplete'), + 'width_entry', + '', + ); + const out = lstsvToXlsform(tsv, { skipValidation: true }); + expect(out.survey[0]).toMatchObject({ appearance: 'autocomplete' }); + }); + test('show_search stored as 1 still reads back as autocomplete', async () => { const tsv = withCell( await toTsv('select_one land', 'autocomplete'),