input_checklist.adoc 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. [#checklist]
  2. = Input: Checklist
  3. The `checklist` type argument renders multiple checkboxes from predefined `choices`. Users can select one or more options, and the selected values are passed to your action as a **JSON array string** (for example `["documents","photos"]`). Legacy comma-separated values are rejected.
  4. [source,yaml]
  5. ----
  6. actions:
  7. - title: Backup selected directories
  8. shell: echo "Backing up: {{ directories }}"
  9. arguments:
  10. - name: directories
  11. title: Directories to back up
  12. type: checklist
  13. choices:
  14. - title: Documents
  15. value: documents
  16. - title: Photos
  17. value: photos
  18. - title: Music
  19. value: music
  20. default: '["documents","photos"]'
  21. ----
  22. .Checklist argument form with Documents and Photos selected by default.
  23. image::args/checklist/checklist.png[]
  24. When the example above runs with Documents and Photos selected, the shell command becomes:
  25. [source,shell]
  26. ----
  27. echo "Backing up: [\"documents\",\"photos\"]"
  28. ----
  29. == Select all / Select none
  30. The web interface includes **Select all** and **Select none** controls above the checkbox list.
  31. == Empty selections
  32. If no options are selected, the argument value is an empty string. Use `rejectNull: true` when at least one selection is required.
  33. [source,yaml]
  34. ----
  35. arguments:
  36. - name: directories
  37. type: checklist
  38. rejectNull: true
  39. choices:
  40. - value: documents
  41. - value: photos
  42. ----
  43. == Choice values
  44. Choice `value` fields may contain commas; selections are encoded as JSON, not joined with commas.
  45. Each `title` is shown in the web interface. If a submitted segment matches a choice `title`, OliveTin maps it to the corresponding `value` before validation, matching the behaviour of xref:args/input_checkbox.adoc[checkbox] arguments with choices.
  46. == Using Entities
  47. Checklist options can be generated from entities, using the same pattern as xref:args/input_dropdown.adoc#args-dropdown-entities[entity-backed dropdowns]. Define one choice template and set `entity` to the entity type name:
  48. [source,yaml]
  49. ----
  50. actions:
  51. - title: Restart selected containers
  52. shell: 'docker restart {{ containers }}'
  53. arguments:
  54. - name: containers
  55. title: Containers to restart
  56. type: checklist
  57. entity: container
  58. choices:
  59. - value: '{{ container.Names }}'
  60. title: '{{ container.Names }}'
  61. entities:
  62. - file: entities/containers.json
  63. name: container
  64. ----
  65. OliveTin expands the template once per entity instance and renders each result as a checkbox. Selected values are still passed as a JSON array string.