Skip to content

Commit b292c72

Browse files
feat(conditional): go to a question after checkbox questions
Checkbox questions get the select "After question N", stored in extraSettings.next: one target for the whole question whichever options are checked, as in Microsoft Forms. Several checked options cannot lead to different targets, so there is no target per option. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
1 parent 22a1ccf commit b292c72

5 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎docs/DataStructure.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,14 @@ Optional extra settings for some [Question Types](#question-types)
271271
| `rows` | `grid` | Array | - | Array of row identifiers / labels for grid questions |
272272
| `questionType` | `grid` | String | `checkbox`, `number`, `radio` | Type of cell for grid questions (checkbox, numeric input, or radio) |
273273
| `goTo` | `dropdown, multiple_unique` | Array | see [Jumps](#jumps) | Where to go next for an answer |
274-
| `next` | `color, file, grid, long, ranking, short` | Integer / string | question id, `'submit'` | Where to go after the question, see [Jumps](#jumps) |
274+
| `next` | `color, file, grid, long, multiple, ranking, short` | Integer / string | question id, `'submit'` | Where to go after the question, see [Jumps](#jumps) |
275275

276276
### Jumps
277277

278278
An answer can lead to a later question or to the end of the form, as in Microsoft and Google Forms. The form stays a flat list of questions.
279279

280280
- `goTo` is a list of jumps per answer: `{"optionId": 12, "target": 34}` for an option, `{"other": true, "target": "submit"}` for the answer "Other". There is at most one jump per answer.
281-
- `next` is one target after the whole question.
281+
- `next` is one target after the whole question; on a checkbox question it applies whichever options are checked.
282282
- A question has either jumps per answer or one jump after the question, depending on its type: `goTo` only on `dropdown` and `multiple_unique`, `next` only on the other types listed above. Sending `next` on a question type with `goTo`, or `goTo` on a question type with `next`, is rejected with 400 "Invalid extraSettings". An answer without a `goTo` entry leads to the following question.
283283
- A target is the id of a later question of the same form or `"submit"` for the end of the form, and `optionId` is the id of an option of the question. Ids of questions of other forms and option ids that are not options of the question are rejected as invalid `extraSettings`; ids of deleted questions of the form are accepted. Without a jump the respondent goes to the following question.
284284
- Jumps never go back: the server removes jumps to the question itself or to an earlier question when a question is updated, reordered or copied, and when a form is copied or imported; copying or importing a form also drops `goTo` or `next` on question types without it. Updating, reordering and copying a question still succeed with their usual status, and the payload keeps its shape: a reorder adds the new `extraSettings` of the questions concerned, and a copied question is returned with its reduced `extraSettings`. The response header `X-Forms-Adjusted` lists the questions that lost jumps, e.g. `removed-jumps=(3 7)`, see [Adjustments by the server](API_v3.md#adjustments-by-the-server).

‎lib/Constants.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ class Constants {
245245
self::ANSWER_TYPE_FILE,
246246
self::ANSWER_TYPE_GRID,
247247
self::ANSWER_TYPE_LONG,
248+
self::ANSWER_TYPE_MULTIPLE,
248249
self::ANSWER_TYPE_RANKING,
249250
self::ANSWER_TYPE_SHORT,
250251
];

‎src/utils/Jumps.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const QUESTION_TYPES_WITH_NEXT = [
2020
'file',
2121
'grid',
2222
'long',
23+
'multiple',
2324
'ranking',
2425
'short',
2526
]

‎tests/Unit/Service/FormsServiceTest.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,11 @@ public static function dataAreExtraSettingsValid() {
17171717
'questionType' => Constants::ANSWER_TYPE_SHORT,
17181718
'expected' => false,
17191719
],
1720+
'jump: next on checkboxes' => [
1721+
'extraSettings' => ['next' => 5],
1722+
'questionType' => Constants::ANSWER_TYPE_MULTIPLE,
1723+
'expected' => true,
1724+
],
17201725
'jump: goTo not offered on checkboxes' => [
17211726
'extraSettings' => ['goTo' => [['optionId' => 11, 'target' => 5]]],
17221727
'questionType' => Constants::ANSWER_TYPE_MULTIPLE,

‎tests/fixtures/jump-paths.json‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@
200200
"answers": { "1": ["12"] },
201201
"visible": [1, 3, 4]
202202
},
203+
{
204+
"name": "a checkbox question has one target whichever options are checked",
205+
"questions": [
206+
{ "id": 1, "type": "multiple", "extraSettings": { "next": 3 } },
207+
{ "id": 2, "type": "short", "extraSettings": {} },
208+
{ "id": 3, "type": "short", "extraSettings": {} }
209+
],
210+
"answers": { "1": ["11", "12"] },
211+
"visible": [1, 3]
212+
},
203213
{
204214
"name": "the jumps of skipped questions do not count",
205215
"questions": [

0 commit comments

Comments
 (0)