Skip to content
Draft
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
4 changes: 2 additions & 2 deletions docs/DataStructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ Optional extra settings for some [Question Types](#question-types)
| `rows` | `grid` | Array | - | Array of row identifiers / labels for grid questions |
| `questionType` | `grid` | String | `checkbox`, `number`, `radio` | Type of cell for grid questions (checkbox, numeric input, or radio) |
| `goTo` | `dropdown, multiple_unique` | Array | see [Jumps](#jumps) | Where to go next for an answer |
| `next` | `color, file, grid, long, ranking, short` | Integer / string | question id, `'submit'` | Where to go after the question, see [Jumps](#jumps) |
| `next` | `color, file, grid, long, multiple, ranking, short` | Integer / string | question id, `'submit'` | Where to go after the question, see [Jumps](#jumps) |

### Jumps

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.

- `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.
- `next` is one target after the whole question.
- `next` is one target after the whole question; on a checkbox question it applies whichever options are checked.
- 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.
- 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.
- 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).
Expand Down
1 change: 1 addition & 0 deletions lib/Constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class Constants {
self::ANSWER_TYPE_FILE,
self::ANSWER_TYPE_GRID,
self::ANSWER_TYPE_LONG,
self::ANSWER_TYPE_MULTIPLE,
self::ANSWER_TYPE_RANKING,
self::ANSWER_TYPE_SHORT,
];
Expand Down
1 change: 1 addition & 0 deletions src/utils/Jumps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const QUESTION_TYPES_WITH_NEXT = [
'file',
'grid',
'long',
'multiple',
'ranking',
'short',
]
Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/Service/FormsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,11 @@ public static function dataAreExtraSettingsValid() {
'questionType' => Constants::ANSWER_TYPE_SHORT,
'expected' => false,
],
'jump: next on checkboxes' => [
'extraSettings' => ['next' => 5],
'questionType' => Constants::ANSWER_TYPE_MULTIPLE,
'expected' => true,
],
'jump: goTo not offered on checkboxes' => [
'extraSettings' => ['goTo' => [['optionId' => 11, 'target' => 5]]],
'questionType' => Constants::ANSWER_TYPE_MULTIPLE,
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/jump-paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@
"answers": { "1": ["12"] },
"visible": [1, 3, 4]
},
{
"name": "a checkbox question has one target whichever options are checked",
"questions": [
{ "id": 1, "type": "multiple", "extraSettings": { "next": 3 } },
{ "id": 2, "type": "short", "extraSettings": {} },
{ "id": 3, "type": "short", "extraSettings": {} }
],
"answers": { "1": ["11", "12"] },
"visible": [1, 3]
},
{
"name": "the jumps of skipped questions do not count",
"questions": [
Expand Down
Loading