|
1 | 1 | <!-- |
2 | | - - SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors |
| 2 | + - SPDX-FileCopyrightText: 2021-2026 Nextcloud GmbH and Nextcloud contributors |
3 | 3 | - SPDX-License-Identifier: AGPL-3.0-only |
4 | 4 | --> |
5 | 5 |
|
@@ -227,6 +227,7 @@ Currently supported Question-Types are: |
227 | 227 | | `file` | One or multiple files. It is possible to specify which mime types are allowed | |
228 | 228 | | `linearscale` | A linear or Likert scale question where you choose an option that best fits your opinion | |
229 | 229 | | `color` | A color answer, hex string representation (e. g. `#123456`) | |
| 230 | +| `conditional` | A conditional branching question with a trigger question and multiple branches containing subquestions | |
230 | 231 |
|
231 | 232 | ## Extra Settings |
232 | 233 |
|
@@ -254,3 +255,189 @@ Optional extra settings for some [Question Types](#question-types) |
254 | 255 | | `optionsHighest` | `linearscale` | Integer | `2, 3, 4, 5, 6, 7, 8, 9, 10` | Set the highest value of the scale, default: `5` | |
255 | 256 | | `optionsLabelLowest` | `linearscale` | string | - | Set the label of the lowest value, default: `'Strongly disagree'` | |
256 | 257 | | `optionsLabelHighest` | `linearscale` | string | - | Set the label of the highest value, default: `'Strongly agree'` | |
| 258 | +| `triggerType` | `conditional` | string | [See trigger types](#conditional-trigger-types) | The type of trigger question (dropdown, multiple_unique, etc.) | |
| 259 | +| `branches` | `conditional` | Array | Array of [Branch objects](#branch-object) | The branches with conditions and subquestions | |
| 260 | + |
| 261 | +## Conditional Questions |
| 262 | + |
| 263 | +Conditional questions enable branching logic in forms. A trigger question determines which branch of subquestions appears based on the respondent's answer. |
| 264 | + |
| 265 | +### Question Properties for Subquestions |
| 266 | + |
| 267 | +Subquestions (questions belonging to a conditional question's branch) have additional properties: |
| 268 | + |
| 269 | +| Property | Type | Description | |
| 270 | +| ---------------- | ------- | -------------------------------------------------------- | |
| 271 | +| parentQuestionId | Integer | The ID of the parent conditional question (null for regular questions) | |
| 272 | +| branchId | String | The ID of the branch this subquestion belongs to | |
| 273 | + |
| 274 | +### Conditional Trigger Types |
| 275 | + |
| 276 | +Supported trigger types for conditional questions: |
| 277 | + |
| 278 | +| Trigger Type | Condition Type | Description | |
| 279 | +| ----------------- | -------------------- | ------------------------------------------------ | |
| 280 | +| `multiple_unique` | `option_selected` | Radio buttons - single option selection | |
| 281 | +| `dropdown` | `option_selected` | Dropdown - single option selection | |
| 282 | +| `multiple` | `options_combination`| Checkboxes - all specified options must be selected | |
| 283 | +| `short` | `string_equals`, `string_contains`, `regex` | Short text with string/regex matching | |
| 284 | +| `long` | `string_contains`, `regex` | Long text with string/regex matching | |
| 285 | +| `linearscale` | `value_equals`, `value_range` | Linear scale with value matching | |
| 286 | +| `date` | `date_range` | Date with date range matching (YYYY-MM-DD) | |
| 287 | +| `time` | `time_range` | Time with time range matching (HH:mm) | |
| 288 | +| `color` | `value_equals` | Color with exact value matching | |
| 289 | +| `file` | `file_uploaded` | File with upload status matching | |
| 290 | + |
| 291 | +### Branch Object |
| 292 | + |
| 293 | +A branch defines conditions and subquestions that appear when those conditions are met. |
| 294 | + |
| 295 | +| Property | Type | Description | |
| 296 | +| ------------ | ------------------------------------------- | --------------------------------------------- | |
| 297 | +| id | String | Unique identifier for the branch | |
| 298 | +| conditions | Array of [Conditions](#condition-object) | Conditions that must be met to show the branch| |
| 299 | +| subQuestions | Array of [Questions](#question) | Questions shown when conditions are met | |
| 300 | + |
| 301 | +```json |
| 302 | +{ |
| 303 | + "id": "branch-1705587600000", |
| 304 | + "conditions": [ |
| 305 | + { "type": "option_selected", "optionId": 42 } |
| 306 | + ], |
| 307 | + "subQuestions": [ |
| 308 | + { |
| 309 | + "id": 101, |
| 310 | + "formId": 3, |
| 311 | + "order": 1, |
| 312 | + "type": "short", |
| 313 | + "text": "Please provide details", |
| 314 | + "parentQuestionId": 100, |
| 315 | + "branchId": "branch-1705587600000" |
| 316 | + } |
| 317 | + ] |
| 318 | +} |
| 319 | +``` |
| 320 | + |
| 321 | +### Condition Object |
| 322 | + |
| 323 | +Conditions determine when a branch is activated. The structure depends on the trigger type. |
| 324 | + |
| 325 | +#### option_selected (for dropdown, multiple_unique) |
| 326 | + |
| 327 | +```json |
| 328 | +{ "type": "option_selected", "optionId": 42 } |
| 329 | +``` |
| 330 | + |
| 331 | +#### options_combination (for multiple/checkboxes) |
| 332 | + |
| 333 | +```json |
| 334 | +{ "type": "options_combination", "optionIds": [42, 43] } |
| 335 | +``` |
| 336 | +All options in `optionIds` must be selected for the branch to activate (AND logic). |
| 337 | + |
| 338 | +#### string_equals (for short text) |
| 339 | + |
| 340 | +```json |
| 341 | +{ "type": "string_equals", "value": "yes" } |
| 342 | +``` |
| 343 | + |
| 344 | +#### string_contains (for short, long text) |
| 345 | + |
| 346 | +```json |
| 347 | +{ "type": "string_contains", "value": "keyword" } |
| 348 | +``` |
| 349 | + |
| 350 | +#### regex (for short, long text) |
| 351 | + |
| 352 | +```json |
| 353 | +{ "type": "regex", "value": "^yes.*" } |
| 354 | +``` |
| 355 | + |
| 356 | +#### value_equals (for color) |
| 357 | + |
| 358 | +```json |
| 359 | +{ "type": "value_equals", "value": "#ff0000" } |
| 360 | +``` |
| 361 | + |
| 362 | +#### value_range (for linearscale, time) |
| 363 | + |
| 364 | +```json |
| 365 | +{ "type": "value_range", "min": 3, "max": 5 } |
| 366 | +``` |
| 367 | + |
| 368 | +#### date_range (for date) |
| 369 | + |
| 370 | +```json |
| 371 | +{ "type": "date_range", "min": "2024-01-01", "max": "2024-12-31" } |
| 372 | +``` |
| 373 | + |
| 374 | +#### time_range (for time) |
| 375 | + |
| 376 | +```json |
| 377 | +{ "type": "time_range", "min": "09:00", "max": "17:00" } |
| 378 | +``` |
| 379 | + |
| 380 | +#### file_uploaded (for file) |
| 381 | + |
| 382 | +```json |
| 383 | +{ "type": "file_uploaded", "fileUploaded": true } |
| 384 | +``` |
| 385 | + |
| 386 | +### Conditional Question Example |
| 387 | + |
| 388 | +A complete conditional question structure: |
| 389 | + |
| 390 | +```json |
| 391 | +{ |
| 392 | + "id": 100, |
| 393 | + "formId": 3, |
| 394 | + "order": 1, |
| 395 | + "type": "conditional", |
| 396 | + "isRequired": true, |
| 397 | + "text": "Do you have any dietary restrictions?", |
| 398 | + "options": [ |
| 399 | + { "id": 42, "questionId": 100, "order": 1, "text": "Yes" }, |
| 400 | + { "id": 43, "questionId": 100, "order": 2, "text": "No" } |
| 401 | + ], |
| 402 | + "extraSettings": { |
| 403 | + "triggerType": "dropdown", |
| 404 | + "branches": [ |
| 405 | + { |
| 406 | + "id": "branch-yes", |
| 407 | + "conditions": [{ "type": "option_selected", "optionId": 42 }], |
| 408 | + "subQuestions": [ |
| 409 | + { |
| 410 | + "id": 101, |
| 411 | + "formId": 3, |
| 412 | + "order": 1, |
| 413 | + "type": "long", |
| 414 | + "text": "Please describe your dietary restrictions", |
| 415 | + "parentQuestionId": 100, |
| 416 | + "branchId": "branch-yes" |
| 417 | + } |
| 418 | + ] |
| 419 | + } |
| 420 | + ] |
| 421 | + } |
| 422 | +} |
| 423 | +``` |
| 424 | + |
| 425 | +### Conditional Answer Structure |
| 426 | + |
| 427 | +When submitting or storing conditional question answers, the structure differs from regular questions: |
| 428 | + |
| 429 | +```json |
| 430 | +{ |
| 431 | + "100": { |
| 432 | + "trigger": ["42"], |
| 433 | + "subQuestions": { |
| 434 | + "101": ["Vegetarian, no nuts"] |
| 435 | + } |
| 436 | + } |
| 437 | +} |
| 438 | +``` |
| 439 | + |
| 440 | +| Property | Type | Description | |
| 441 | +| ------------ | --------------------------- | ----------------------------------------------------- | |
| 442 | +| trigger | Array of strings | Answer values for the trigger question | |
| 443 | +| subQuestions | Object (questionId → Array) | Map of subquestion IDs to their answer value arrays | |
0 commit comments