# Select Missing Words & Sequence Order — Admin Panel Integration Guide This guide explains how to **render, edit, validate, and serialize** the dynamic question builder components **`SELECT_MISSING_WORDS`** and **`SEQUENCE_ORDER`** in the Yimaru admin panel. It is written to match the **existing admin UI patterns** already used for: - **Fill in the blank** → stimulus `SELECT_MISSING_WORDS` (segment builder + word bank) - **Matching** → stimulus `MATCHING_INPUTS` (paired row list) > **Scope:** Admin question authoring for `DYNAMIC` questions (`dynamic_payload.stimulus` / `dynamic_payload.response`). > **Backend source of truth for kinds:** `internal/domain/question_type_builder.go` > **Related:** `docs/question-type-definition-groups-admin-panel-integration.md`, Postman collection `postman/Dynamic-Question-Type-Builder.postman_collection.json` --- ## Table of contents 1. [Summary](#summary) 2. [How schema-driven rendering works](#how-schema-driven-rendering-works) 3. [Shared UI shell (STIMULUS / RESPONSE sections)](#shared-ui-shell-stimulus--response-sections) 4. [SELECT_MISSING_WORDS](#select_missing_words) 5. [SEQUENCE_ORDER](#sequence_order) 6. [TypeScript types](#typescript-types) 7. [Serialization helpers](#serialization-helpers) 8. [Client-side validation](#client-side-validation) 9. [React component patterns](#react-component-patterns) 10. [Full API examples](#full-api-examples) 11. [Comparison with Matching & Fill in the blank](#comparison-with-matching--fill-in-the-blank) 12. [Error handling](#error-handling) 13. [Integration checklist](#integration-checklist) 14. [Quick reference](#quick-reference) --- ## Summary | Component kind | Typical section | Admin UI pattern | Stored in `value` | |----------------|-----------------|------------------|-------------------| | `SELECT_MISSING_WORDS` | **Stimulus** | Alternating **Text** / **Blank** blocks + **Word bank** rows | `segments`, `word_bank`, `allow_reuse` | | `SELECT_MISSING_WORDS` | **Response** | Per-blank correct answer picker (dropdown from bank) | `blanks[]` with `blank_id`, `text`, `word_id` | | `SEQUENCE_ORDER` | **Response only** | Ordered **item rows** with drag-reorder (like Matching rows, single column) | `items[]`, `correct_order[]` | ### Backend validation today The API validates: - Element `id` + `kind` presence - Kinds allowed by the selected **question type definition** - Required schema element ids present The API **does not** currently validate the inner shape of `value` objects for these kinds. The admin panel should enforce the conventions below so learner apps and future server validators stay consistent. ### Runtime mapping | Response kind | Legacy `question_type` used internally | API `question_type` on question row | |---------------|----------------------------------------|-------------------------------------| | `SELECT_MISSING_WORDS` | `SHORT_ANSWER` | `DYNAMIC` | | `SEQUENCE_ORDER` | `DYNAMIC` (auxiliary / builder-native) | `DYNAMIC` | **Do not** send top-level `options`, `short_answers`, or `question_text` for these dynamic questions. Content lives entirely in `dynamic_payload`. --- ## How schema-driven rendering works Each question is authored against a **question type definition**: ```http GET /api/v1/questions/type-definitions/:id ``` The definition provides: | Field | Use in admin UI | |-------|-----------------| | `stimulus_schema[]` | Ordered list of stimulus slots to render under **STIMULUS** | | `response_schema[]` | Ordered list of response slots to render under **RESPONSE** | | `*.id` | Must match `dynamic_payload.*[].id` when saving | | `*.kind` | Chooses which React renderer to mount | | `*.label` | Section heading (e.g. `"Passage with blanks"`) | | `*.required` | Show `*` and block save when empty | | `*.config` | Min/max limits for lists (blanks, words, items) | ```mermaid flowchart TD A[Load question type definition] --> B[Render stimulus_schema slots] A --> C[Render response_schema slots] B --> D{kind?} D -->|SELECT_MISSING_WORDS| E[Segment + word bank editor] D -->|INSTRUCTION / TEXT_PASSAGE| F[Text area] D -->|MATCHING_INPUTS| G[Left/right row editor] C --> H{kind?} H -->|SELECT_MISSING_WORDS| I[Blank answer key editor] H -->|SEQUENCE_ORDER| J[Sequence item + order editor] E --> K[Build dynamic_payload JSON] I --> K J --> K K --> L[POST or PUT /api/v1/questions] ``` When **editing** an existing question, hydrate local form state from `question.dynamic_payload` by matching `element.id` to schema slot `id`. --- ## Shared UI shell (STIMULUS / RESPONSE sections) Match the layout used for Matching and Fill in the blank: ``` ┌─ STIMULUS ─────────────────────────────────────────────────────┐ │ [purple micro-label] STIMULUS │ │ ┌─ Instruction banner (optional) ───────────────────────────┐ │ │ │ Image, audio, and PDF use upload or URL. Table uses the │ │ │ │ visual table builder. Timer and prep-time slots use seconds.│ │ │ │ Other slots use text or structured JSON where noted. │ │ │ └────────────────────────────────────────────────────────────┘ │ │ … one card per stimulus_schema element … │ └──────────────────────────────────────────────────────────────────┘ ┌─ RESPONSE ─────────────────────────────────────────────────────┐ │ [purple micro-label] RESPONSE │ │ … one card per response_schema element … │ └──────────────────────────────────────────────────────────────────┘ ``` ### Card anatomy (same as Matching rows) | UI element | Spec | |------------|------| | Section label | `STIMULUS` / `RESPONSE` — small caps, purple (`#7C3AED` or your design token) | | Card title | `schema.label` + red `*` when `required` | | Primary action | Outlined purple button top-right (`+ Add row`, `+ Add word`, `+ Add item`) | | Row container | White card, `1px` light border, `8–12px` radius, padding `12–16px` | | Field micro-labels | Gray uppercase (`LEFT L1`, `BLANK B1`, `ITEM S1`) | | Delete | Trash icon button, right edge of row | | Helper text | Gray `12–13px` under the card | --- ## SELECT_MISSING_WORDS Used for **cloze / gap-fill / word-bank** tasks. The system definition `fill_in_the_blank` allows this kind on **both** stimulus and response. ### Stimulus UI — passage builder + word bank This is the UI shown in your **Fill in the blank** screenshot: alternating **Blank** chips and **Text** areas, plus a **WORD BANK** list. #### Visual layout ``` ┌─ Passage with blanks * ─────────────────────────── [+ Add text] [+ Add blank] ─┐ │ │ │ ┌ Blank b1 ─────────────────────────────────────────────────────── [🗑] ─┐ │ │ │ (purple/lavender pill — not editable, only identifies the slot) │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ┌ TEXT ─────────────────────────────────────────────────────────── [🗑] ─┐ │ │ │ [ multiline: "Text before or after a blank" ] │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ┌ Blank b2 ─────────────────────────────────────────────────────── [🗑] ─┐ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ │ ┌ TEXT ─────────────────────────────────────────────────────────── [🗑] ─┐ │ │ │ [ multiline textarea ] │ │ │ └─────────────────────────────────────────────────────────────────────────┘ │ │ │ │ Helper: Passage must contain at least one blank. Text before/after blanks │ │ is preserved exactly (including spaces). │ └───────────────────────────────────────────────────────────────────────────────┘ ┌─ WORD BANK ─────────────────────────────────────────────── [+ Add word] ─┐ │ w1 [ Word 1________________________ ] [🗑] │ │ w2 [ Word 2________________________ ] [🗑] │ │ Helper: Add decoy words; not every word must be used in the answer. │ └─────────────────────────────────────────────────────────────────────────────┘ ┌─ Options ─────────────────────────────────────────────────────────────────┐ │ [ ] Allow reusing the same word for multiple blanks (allow_reuse) │ └─────────────────────────────────────────────────────────────────────────────┘ ``` #### Block types | Block | Admin control | Maps to `segments[]` | |-------|---------------|----------------------| | **Text** | Multiline textarea | `{ "type": "text", "value": "" }` | | **Blank** | Non-editable pill showing `b1`, `b2`, … | `{ "type": "blank", "id": "b1" }` | #### ID generation rules | Entity | Pattern | Example | |--------|---------|---------| | Blank ids | `b` + monotonic number | `b1`, `b2`, `b3` | | Word bank ids | `w` + monotonic number | `w1`, `w2`, `w3` | - Generate ids **once** when a row/block is created; **never** renumber on delete (keeps response answers stable). - Display labels (`Blank b1`, `w1`) are derived from ids for the admin UI only. #### Recommended block toolbar actions | Button | Behavior | |--------|----------| | `+ Add text` | Appends a text segment block at end | | `+ Add blank` | Appends a blank segment; auto-suggest next `bN` id | | Drag handle (optional) | Reorder blocks in `segments` array | | 🗑 on block | Remove segment; if blank removed, also remove linked response answer | #### `value` JSON shape (stimulus) ```json { "segments": [ { "type": "text", "value": "Yesterday I " }, { "type": "blank", "id": "b1" }, { "type": "text", "value": " to school and " }, { "type": "blank", "id": "b2" }, { "type": "text", "value": " my homework." } ], "word_bank": [ { "id": "w1", "text": "went" }, { "id": "w2", "text": "did" }, { "id": "w3", "text": "go" }, { "id": "w4", "text": "do" } ], "allow_reuse": false } ``` | Field | Type | Required | Notes | |-------|------|----------|-------| | `segments` | array | Yes | Alternating text + blank; order = display order | | `segments[].type` | `"text"` \| `"blank"` | Yes | | | `segments[].value` | string | When `type=text` | Preserve whitespace | | `segments[].id` | string | When `type=blank` | Unique within this question | | `word_bank` | array | Yes (for bank-style UI) | Min 1 word recommended | | `word_bank[].id` | string | Yes | Stable id | | `word_bank[].text` | string | Yes | Trim for display; preserve internal spaces if entered | | `allow_reuse` | boolean | No | Default `false` | #### Schema `config` hints (definition authoring) ```json { "id": "cloze", "kind": "SELECT_MISSING_WORDS", "label": "Passage with blanks", "required": true, "config": { "min_blanks": 1, "max_blanks": 10, "min_word_bank": 2, "max_word_bank": 20 } } ``` Enforce `min_*` / `max_*` in the admin UI before save. --- ### Response UI — correct answers per blank Render **one row per blank** discovered from the **stimulus** `segments` (do not let admins invent blank ids only in response). ``` ┌─ Correct selections * ──────────────────────────────────────────────────────┐ │ BLANK B1 [ dropdown: went ▼ ] or [ text: went________ ] │ │ BLANK B2 [ dropdown: did ▼ ] or [ text: did_________ ] │ │ Helper: Each blank must have an answer. Duplicates disallowed unless reuse on.│ └───────────────────────────────────────────────────────────────────────────────┘ ``` #### Interaction rules | Rule | Behavior | |------|----------| | Dropdown source | Stimulus `word_bank` entries (`id` + `text`) | | On stimulus blank deleted | Remove corresponding response row | | On stimulus blank added | Add empty response row for that `blank_id` | | `word_id` | Set when picked from bank; omit if admin types free text | | `text` | Always store the canonical answer string (from bank or typed) | #### `value` JSON shape (response) ```json { "blanks": [ { "blank_id": "b1", "text": "went", "word_id": "w1" }, { "blank_id": "b2", "text": "did", "word_id": "w2" } ] } ``` | Field | Type | Required | Notes | |-------|------|----------|-------| | `blanks` | array | Yes | One entry per stimulus blank | | `blanks[].blank_id` | string | Yes | Matches stimulus blank `id` | | `blanks[].text` | string | Yes | Grading string | | `blanks[].word_id` | string | No | Links to `word_bank[].id` when selected from bank | --- ### Stimulus + response on the same question For `fill_in_the_blank` and custom cloze types you often have: | Slot | Kind | Role | |------|------|------| | Stimulus `passage_intro` | `TEXT_PASSAGE` or `INSTRUCTION` | Top-level task text | | Stimulus `cloze` | `SELECT_MISSING_WORDS` | Segment builder + word bank | | Response `cloze_answer` | `SELECT_MISSING_WORDS` | Answer key | The segment/word-bank UI mounts only on the stimulus `SELECT_MISSING_WORDS` slot. The response slot mounts the per-blank answer editor. **Important:** If the definition includes only `SELECT_MISSING_WORDS` in stimulus with **no** `QUESTION_TEXT`, `INSTRUCTION`, or `TEXT_PASSAGE`, the stored search/activity `question_text` may be empty. Prefer definitions that include at least one text stimulus kind for discoverability. --- ## SEQUENCE_ORDER `SEQUENCE_ORDER` is a **response-side** kind (ordering / sequencing tasks). There is **no** dedicated stimulus kind for items — items and correct order are authored together in the response slot. ### Typical type definition ```json { "key": "sequence_ordering", "display_name": "Sequence Order", "description": "Learner arranges items in the correct order.", "stimulus_component_kinds": ["INSTRUCTION"], "response_component_kinds": ["SEQUENCE_ORDER"], "stimulus_schema": [ { "id": "instruction", "kind": "INSTRUCTION", "label": "Instructions", "required": true } ], "response_schema": [ { "id": "ordering", "kind": "SEQUENCE_ORDER", "label": "Sequence items", "required": true, "config": { "min_items": 2, "max_items": 12 } } ], "status": "ACTIVE" } ``` ### Response UI — sequence item list (admin canonical order) Mirror the **Matching inputs** row pattern, but with a **single column** and **drag-to-reorder** handles. The **vertical order in the admin list is the correct order** learners must produce. ``` ┌─ Sequence items * ─────────────────────────────────────── [+ Add item] ─┐ │ Helper: Minimum 2 items. Drag to set the correct order. Whitespace │ │ in text is preserved. Learners see items shuffled at runtime. │ │ │ │ ≡ ITEM S1 [ First step_______________________________ ] [🗑] │ │ ≡ ITEM S2 [ Second step______________________________ ] [🗑] │ │ ≡ ITEM S3 [ Third step_______________________________ ] [🗑] │ │ ≡ ITEM S4 [ Fourth step______________________________ ] [🗑] │ └──────────────────────────────────────────────────────────────────────────┘ ``` #### UI elements | Element | Spec | |---------|------| | `≡` drag handle | Reorders rows; updates `correct_order` | | Micro-label | `ITEM S1`, `ITEM S2`, … from item `id` | | Text input | Single-line; placeholder `Item 1`, `Item 2`, … | | `+ Add item` | Appends row with next `sN` id | | 🗑 | Removes item; also remove id from `correct_order` | #### ID generation | Entity | Pattern | Example | |--------|---------|---------| | Sequence item ids | `s` + monotonic number | `s1`, `s2`, `s3` | Same rule as blanks: **stable ids** across edits; do not renumber on delete. #### `value` JSON shape (response) ```json { "items": [ { "id": "s1", "text": "Preheat the oven" }, { "id": "s2", "text": "Mix the ingredients" }, { "id": "s3", "text": "Pour into a pan" }, { "id": "s4", "text": "Bake for 25 minutes" } ], "correct_order": ["s1", "s2", "s3", "s4"] } ``` | Field | Type | Required | Notes | |-------|------|----------|-------| | `items` | array | Yes | Pool of sequence steps | | `items[].id` | string | Yes | Stable identifier | | `items[].text` | string | Yes | Display text | | `correct_order` | string[] | Yes | Permutation of `items[].id`; admin list top-to-bottom | #### Serialization rule On every drag or row edit: ```text correct_order = items.map(item => item.id) // after visual reorder ``` On load from API: ```text items = order items by index of id in correct_order // if correct_order missing or invalid, fall back to items array order ``` #### Schema `config` | Config key | Default | Admin enforcement | |------------|---------|-------------------| | `min_items` | `2` | Block save below minimum | | `max_items` | `12` | Disable `+ Add item` at max | Postman example uses `max_items: 8`; treat schema config as authoritative per definition. ### Learner preview (admin optional) | Mode | Behavior | |------|----------| | Authoring | Show ordered list (canonical answer) | | Preview | Shuffle a copy of `items` for display; learner drags to match `correct_order` | Shuffle for preview only — never mutate stored `correct_order`. ### Combining with other response kinds Definitions may pair `SEQUENCE_ORDER` with `ANSWER_TIMER` or `OPTION` (see Postman). Render each response schema slot as its own card; only the `SEQUENCE_ORDER` slot uses the sequence editor. --- ## TypeScript types ```typescript /** Matches dynamic_payload root */ export interface DynamicQuestionPayload { stimulus: DynamicElementInstance[]; response: DynamicElementInstance[]; } export interface DynamicElementInstance { id: string; kind: string; value?: unknown; meta?: Record; } /** SELECT_MISSING_WORDS — stimulus */ export type ClozeSegment = | { type: "text"; value: string } | { type: "blank"; id: string }; export interface ClozeStimulusValue { segments: ClozeSegment[]; word_bank: Array<{ id: string; text: string }>; allow_reuse?: boolean; } /** SELECT_MISSING_WORDS — response */ export interface ClozeResponseValue { blanks: Array<{ blank_id: string; text: string; word_id?: string; }>; } /** SEQUENCE_ORDER — response */ export interface SequenceOrderValue { items: Array<{ id: string; text: string }>; correct_order: string[]; } /** Local admin form state (stimulus cloze) */ export interface ClozeStimulusFormState { blocks: Array< | { kind: "text"; clientKey: string; value: string } | { kind: "blank"; clientKey: string; id: string } >; wordBank: Array<{ id: string; text: string; clientKey: string }>; allowReuse: boolean; } /** Local admin form state (sequence) */ export interface SequenceOrderFormState { items: Array<{ id: string; text: string; clientKey: string }>; } ``` --- ## Serialization helpers ### Cloze: form → API (stimulus) ```typescript export function clozeStimulusToValue(state: ClozeStimulusFormState): ClozeStimulusValue { return { segments: state.blocks.map((block) => block.kind === "text" ? { type: "text", value: block.value } : { type: "blank", id: block.id } ), word_bank: state.wordBank.map((w) => ({ id: w.id, text: w.text })), allow_reuse: state.allowReuse, }; } ``` ### Cloze: API → form (stimulus) ```typescript export function clozeStimulusFromValue(value: ClozeStimulusValue): ClozeStimulusFormState { return { blocks: value.segments.map((seg, i) => seg.type === "text" ? { kind: "text", clientKey: `t-${i}`, value: seg.value } : { kind: "blank", clientKey: `b-${seg.id}`, id: seg.id } ), wordBank: value.word_bank.map((w) => ({ id: w.id, text: w.text, clientKey: `w-${w.id}`, })), allowReuse: value.allow_reuse ?? false, }; } ``` ### Cloze: blank ids from stimulus (for response editor) ```typescript export function listBlankIds(stimulus: ClozeStimulusValue): string[] { return stimulus.segments .filter((s): s is { type: "blank"; id: string } => s.type === "blank") .map((s) => s.id); } ``` ### Sequence: form → API ```typescript export function sequenceOrderToValue(state: SequenceOrderFormState): SequenceOrderValue { const items = state.items.map((i) => ({ id: i.id, text: i.text })); return { items, correct_order: items.map((i) => i.id), }; } ``` ### Sequence: API → form ```typescript export function sequenceOrderFromValue(value: SequenceOrderValue): SequenceOrderFormState { const byId = new Map(value.items.map((i) => [i.id, i])); const ordered = value.correct_order?.length > 0 ? value.correct_order.map((id) => byId.get(id)).filter(Boolean) : value.items; return { items: ordered.map((i) => ({ id: i!.id, text: i!.text, clientKey: `s-${i!.id}`, })), }; } ``` ### Building `dynamic_payload` for save ```typescript function upsertElement( list: DynamicElementInstance[], slot: { id: string; kind: string }, value: unknown ): DynamicElementInstance[] { const idx = list.findIndex((e) => e.id === slot.id); const el: DynamicElementInstance = { id: slot.id, kind: slot.kind, value }; if (idx === -1) return [...list, el]; const next = [...list]; next[idx] = el; return next; } ``` --- ## Client-side validation Validate before `POST /api/v1/questions` or `PUT /api/v1/questions/:id`. ### SELECT_MISSING_WORDS (stimulus) | Check | Error message | |-------|---------------| | ≥ 1 blank segment | `Add at least one blank` | | ≤ `max_blanks` | `Too many blanks (max N)` | | Each text segment not only whitespace | `Text segments cannot be empty` | | Blank ids unique | `Duplicate blank id` | | ≥ `min_word_bank` words | `Add at least N words to the bank` | | Word texts non-empty | `Word bank entries cannot be empty` | | Word ids unique | `Duplicate word id` | ### SELECT_MISSING_WORDS (response) | Check | Error message | |-------|---------------| | Every stimulus blank has an answer | `Missing answer for blank b2` | | Answer `text` non-empty | `Answer for b1 cannot be empty` | | If `!allow_reuse` | Same `word_id` cannot appear twice | | `blank_id` set matches stimulus | `Unknown blank_id in response` | ### SEQUENCE_ORDER (response) | Check | Error message | |-------|---------------| | ≥ `min_items` (default 2) | `Add at least 2 sequence items` | | ≤ `max_items` | `Too many items (max N)` | | Item texts non-empty | `Sequence item cannot be empty` | | Item ids unique | `Duplicate item id` | | `correct_order` length = `items.length` | `Correct order must include every item` | | `correct_order` ids ⊆ `items` ids | `Invalid id in correct_order` | --- ## React component patterns ### Registry map (extend your existing dynamic renderer) ```typescript const STIMULUS_RENDERERS: Record> = { SELECT_MISSING_WORDS: ClozeStimulusEditor, MATCHING_INPUTS: MatchingInputsEditor, INSTRUCTION: InstructionTextarea, TEXT_PASSAGE: TextPassageTextarea, // … }; const RESPONSE_RENDERERS: Record> = { SELECT_MISSING_WORDS: ClozeResponseEditor, SEQUENCE_ORDER: SequenceOrderEditor, MATCHING_ANSWER: MatchingAnswerEditor, // … }; interface SlotRendererProps { schema: DynamicElementDefinition; value: unknown; onChange: (value: unknown) => void; /** Stimulus cloze answers need stimulus cloze value */ stimulusContext?: DynamicQuestionPayload["stimulus"]; } ``` ### `ClozeStimulusEditor` responsibilities 1. Render block list (blank pills + text areas). 2. Render word bank section (`WORD BANK` header + `+ Add word`). 3. Optional `allow_reuse` checkbox. 4. Emit `ClozeStimulusValue` on change. ### `ClozeResponseEditor` responsibilities 1. Find sibling stimulus element with `kind === "SELECT_MISSING_WORDS"`. 2. Parse blank ids from that stimulus value. 3. Render one answer control per blank. 4. Emit `ClozeResponseValue`. ### `SequenceOrderEditor` responsibilities 1. Render ordered rows with drag-and-drop (`@dnd-kit` or similar). 2. `+ Add item` / delete row. 3. Keep `correct_order` in sync with visual order on every reorder. ### Suggested component tree ``` {stimulusSchema.map(slot => ( {renderStimulus(slot)} ))} {responseSchema.map(slot => ( {renderResponse(slot)} ))} ``` --- ## Full API examples ### Example A — Word-bank cloze (custom definition) **Create definition** (once): ```http POST /api/v1/questions/type-definitions Authorization: Bearer Content-Type: application/json ``` ```json { "key": "word_bank_cloze", "display_name": "Word Bank Cloze", "stimulus_component_kinds": ["INSTRUCTION", "SELECT_MISSING_WORDS"], "response_component_kinds": ["SELECT_MISSING_WORDS"], "stimulus_schema": [ { "id": "instruction", "kind": "INSTRUCTION", "label": "Instructions", "required": true }, { "id": "cloze", "kind": "SELECT_MISSING_WORDS", "label": "Passage with blanks", "required": true, "config": { "min_blanks": 1, "max_blanks": 10, "min_word_bank": 2 } } ], "response_schema": [ { "id": "cloze_answer", "kind": "SELECT_MISSING_WORDS", "label": "Correct selections", "required": true } ], "status": "ACTIVE" } ``` **Create question:** ```http POST /api/v1/questions ``` ```json { "question_type": "DYNAMIC", "question_type_definition_id": 8, "difficulty_level": "MEDIUM", "points": 2, "status": "DRAFT", "dynamic_payload": { "stimulus": [ { "id": "instruction", "kind": "INSTRUCTION", "value": "Select the correct word from the bank for each blank." }, { "id": "cloze", "kind": "SELECT_MISSING_WORDS", "value": { "segments": [ { "type": "text", "value": "Yesterday I " }, { "type": "blank", "id": "b1" }, { "type": "text", "value": " to school and " }, { "type": "blank", "id": "b2" }, { "type": "text", "value": " my homework." } ], "word_bank": [ { "id": "w1", "text": "went" }, { "id": "w2", "text": "did" }, { "id": "w3", "text": "go" }, { "id": "w4", "text": "do" } ], "allow_reuse": false } } ], "response": [ { "id": "cloze_answer", "kind": "SELECT_MISSING_WORDS", "value": { "blanks": [ { "blank_id": "b1", "text": "went", "word_id": "w1" }, { "blank_id": "b2", "text": "did", "word_id": "w2" } ] } } ] } } ``` ### Example B — System `fill_in_the_blank` (id often `3`) Uses `TEXT_PASSAGE` instead of `INSTRUCTION` for intro text; same cloze UI for the `SELECT_MISSING_WORDS` stimulus slot. ### Example C — Sequence order ```json { "question_type": "DYNAMIC", "question_type_definition_id": 12, "difficulty_level": "EASY", "points": 1, "status": "DRAFT", "dynamic_payload": { "stimulus": [ { "id": "instruction", "kind": "INSTRUCTION", "value": "Put the steps of making tea in the correct order." } ], "response": [ { "id": "ordering", "kind": "SEQUENCE_ORDER", "value": { "items": [ { "id": "s1", "text": "Boil water" }, { "id": "s2", "text": "Put tea bag in cup" }, { "id": "s3", "text": "Pour hot water" }, { "id": "s4", "text": "Steep for 3 minutes" } ], "correct_order": ["s1", "s2", "s3", "s4"] } } ] } } ``` --- ## Comparison with Matching & Fill in the blank | Aspect | Matching (`MATCHING_INPUTS`) | Fill in blank (`SELECT_MISSING_WORDS` stimulus) | Sequence (`SEQUENCE_ORDER`) | |--------|------------------------------|-----------------------------------------------|-----------------------------| | Section | Stimulus | Stimulus (+ optional text slot) | Response only | | Row layout | Two columns (LEFT / RIGHT) | Text blocks + blank pills | Single column + drag handle | | List action | `+ Add row` | `+ Add text`, `+ Add blank`, `+ Add word` | `+ Add item` | | Stable ids | `l1`, `r1` | `b1`, `w1` | `s1` | | Answer side | `MATCHING_ANSWER` pairs | `SELECT_MISSING_WORDS` blanks[] | `correct_order[]` | | Whitespace | Preserved in item text | Preserved in text segments | Preserved in item text | | Min count | 2 pairs | 1 blank, 2+ bank words | 2 items | --- ## Error handling | API error | Typical cause | Admin action | |-----------|---------------|--------------| | `400 Invalid dynamic_payload` | Missing required schema slot id | Ensure every `required` schema id exists in payload | | `400 dynamic_payload is required` | Missing payload on create | Build payload before save | | `400 question_text is not used for DYNAMIC` | Sent top-level `question_text` | Remove; use stimulus text kinds | | `400 kind X is not allowed` | Kind not in definition | Reload definition; remount correct renderer | Show server `error` string in a toast; map known client validation errors inline on the relevant card. --- ## Integration checklist ### SELECT_MISSING_WORDS - [ ] Stimulus renderer: alternating text + blank blocks matching Fill in the blank screenshot - [ ] Word bank section with `WORD BANK` label and `+ Add word` - [ ] Stable `bN` / `wN` ids (no renumber on delete) - [ ] `allow_reuse` toggle when definition allows bank reuse - [ ] Response renderer: one answer row per stimulus blank - [ ] Dropdown answers sourced from stimulus `word_bank` - [ ] Serialize / deserialize `segments`, `word_bank`, `blanks` - [ ] Client validation before save - [ ] Cross-slot sync when blanks added/removed in stimulus ### SEQUENCE_ORDER - [ ] Response-only card under **RESPONSE** section - [ ] Row UI aligned with Matching (bordered rows, micro-labels, trash, `+ Add item`) - [ ] Drag-and-drop reorder updates `correct_order` - [ ] Stable `sN` item ids - [ ] Enforce `min_items` / `max_items` from schema `config` - [ ] Optional learner preview with shuffled items - [ ] Serialize / deserialize `items` + `correct_order` ### Shared - [ ] Registry maps `kind` → editor component for stimulus/response - [ ] Load definition schema before rendering question form - [ ] `upsertElement` by schema slot `id` on save - [ ] Do not send `question_text` for `DYNAMIC` questions - [ ] Practice full-update flows pass `dynamic_payload` unchanged in shape --- ## Quick reference ### Component kinds ``` Stimulus: SELECT_MISSING_WORDS Response: SELECT_MISSING_WORDS | SEQUENCE_ORDER ``` ### Minimal valid values ```json // Stimulus SELECT_MISSING_WORDS { "segments": [ { "type": "text", "value": "Hello " }, { "type": "blank", "id": "b1" }, { "type": "text", "value": " world" } ], "word_bank": [{ "id": "w1", "text": "big" }], "allow_reuse": false } // Response SELECT_MISSING_WORDS { "blanks": [{ "blank_id": "b1", "text": "big", "word_id": "w1" }] } // Response SEQUENCE_ORDER { "items": [ { "id": "s1", "text": "Step A" }, { "id": "s2", "text": "Step B" } ], "correct_order": ["s1", "s2"] } ``` ### APIs | Action | Endpoint | |--------|----------| | Component catalog | `GET /api/v1/questions/component-catalog` | | Load definition | `GET /api/v1/questions/type-definitions/:id` | | Create question | `POST /api/v1/questions` | | Update question | `PUT /api/v1/questions/:id` | | List questions in practice | `GET /api/v1/question-sets/:setId/questions` | --- *Document version: 2026-06-18 — aligns with backend `production` branch component catalog and dynamic payload conventions.*