input_checklist.adoc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 comma-separated string.
  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. When the example above runs with Documents and Photos selected, the shell command becomes:
  23. [source,shell]
  24. ----
  25. echo "Backing up: documents,photos"
  26. ----
  27. == Select all / Select none
  28. The web interface includes **Select all** and **Select none** controls above the checkbox list.
  29. == Empty selections
  30. If no options are selected, the argument value is an empty string. Use `rejectNull: true` when at least one selection is required.
  31. [source,yaml]
  32. ----
  33. arguments:
  34. - name: directories
  35. type: checklist
  36. rejectNull: true
  37. choices:
  38. - value: documents
  39. - value: photos
  40. ----
  41. == Choice values
  42. Choice `value` fields must not contain commas, because commas are used to join multiple selections together.
  43. 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.
  44. == Using Entities
  45. 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:
  46. [source,yaml]
  47. ----
  48. actions:
  49. - title: Restart selected containers
  50. shell: 'docker restart {{ containers }}'
  51. arguments:
  52. - name: containers
  53. title: Containers to restart
  54. type: checklist
  55. entity: container
  56. choices:
  57. - value: '{{ container.Names }}'
  58. title: '{{ container.Names }}'
  59. entities:
  60. - file: entities/containers.json
  61. name: container
  62. ----
  63. OliveTin expands the template once per entity instance and renders each result as a checkbox. Selected values are still passed as a comma-separated string.