{
  "version": "1.0",
  "name": "Multi-choice Selector",
  "template": "{\"type\":\"Card\",\"asForm\":true,\"size\":\"md\",\"confirm\":{\"label\":\"Submit\",\"action\":{\"type\":\"submit\",\"payload\":{\"max\":{{ (maxSelections) | tojson }}},\"requestAssistantResponse\":true}},\"children\":[{\"type\":\"Col\",\"gap\":2,\"children\":[{\"type\":\"Title\",\"value\":{{ (title) | tojson }},\"size\":\"sm\"},{\"type\":\"Row\",\"children\":[{\"type\":\"Caption\",\"value\":{{ ((\"Select up to \" ~ maxSelections)) | tojson }}},{\"type\":\"Spacer\"},{\"type\":\"Caption\",\"value\":{{ ((selectedCount ~ \"/\" ~ maxSelections ~ \" selected\")) | tojson }},\"color\":\"emphasis\"}]}]},{\"type\":\"Divider\",\"flush\":true},{\"type\":\"ListView\",\"limit\":30,\"children\":[{%- set _c -%}{%-for item in options -%},{\"type\":\"ListViewItem\",\"key\":{{ (item.id) | tojson }},\"align\":\"center\",\"children\":[{\"type\":\"Checkbox\",\"name\":{{ ((\"choices.\" ~ item.id)) | tojson }},\"label\":{{ (item.label) | tojson }},\"defaultChecked\":{{ (item.checked) | tojson }},\"disabled\":{{ ((selectedCount >= maxSelections) and (not item.checked)) | tojson }},\"onChangeAction\":{\"type\":\"choices.toggle\",\"payload\":{\"id\":{{ (item.id) | tojson }}}}}]}{%-endfor-%}{%- endset -%}{{- (_c[1:] if _c and _c[0] == ',' else _c) -}}]}]}",
  "jsonSchema": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "title": {
        "type": "string"
      },
      "maxSelections": {
        "type": "integer",
        "minimum": 1,
        "maximum": 30
      },
      "selectedCount": {
        "type": "integer",
        "minimum": 0,
        "maximum": 30
      },
      "options": {
        "minItems": 1,
        "maxItems": 30,
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "id": {
              "type": "string"
            },
            "label": {
              "type": "string"
            },
            "checked": {
              "type": "boolean"
            }
          },
          "required": [
            "id",
            "label",
            "checked"
          ],
          "additionalProperties": false
        }
      }
    },
    "required": [
      "title",
      "maxSelections",
      "selectedCount",
      "options"
    ],
    "additionalProperties": false
  },
  "outputJsonPreview": {
    "type": "Card",
    "asForm": true,
    "size": "md",
    "confirm": {
      "label": "Submit",
      "action": {
        "type": "submit",
        "payload": {
          "max": 3
        },
        "requestAssistantResponse": true
      }
    },
    "children": [
      {
        "type": "Col",
        "gap": 2,
        "children": [
          {
            "type": "Title",
            "value": "Pick your options",
            "size": "sm"
          },
          {
            "type": "Row",
            "children": [
              {
                "type": "Caption",
                "value": "Select up to 3"
              },
              {
                "type": "Spacer"
              },
              {
                "type": "Caption",
                "value": "2/3 selected",
                "color": "emphasis"
              }
            ]
          }
        ]
      },
      {
        "type": "Divider",
        "flush": true
      },
      {
        "type": "ListView",
        "limit": 30,
        "children": [
          {
            "type": "ListViewItem",
            "key": "opt1",
            "align": "center",
            "children": [
              {
                "type": "Checkbox",
                "name": "choices.opt1",
                "label": "Option 1",
                "defaultChecked": true,
                "disabled": false,
                "onChangeAction": {
                  "type": "choices.toggle",
                  "payload": {
                    "id": "opt1"
                  }
                }
              }
            ]
          },
          {
            "type": "ListViewItem",
            "key": "opt2",
            "align": "center",
            "children": [
              {
                "type": "Checkbox",
                "name": "choices.opt2",
                "label": "Option 2",
                "defaultChecked": true,
                "disabled": false,
                "onChangeAction": {
                  "type": "choices.toggle",
                  "payload": {
                    "id": "opt2"
                  }
                }
              }
            ]
          },
          {
            "type": "ListViewItem",
            "key": "opt3",
            "align": "center",
            "children": [
              {
                "type": "Checkbox",
                "name": "choices.opt3",
                "label": "Option 3",
                "defaultChecked": false,
                "disabled": false,
                "onChangeAction": {
                  "type": "choices.toggle",
                  "payload": {
                    "id": "opt3"
                  }
                }
              }
            ]
          },
          {
            "type": "ListViewItem",
            "key": "opt4",
            "align": "center",
            "children": [
              {
                "type": "Checkbox",
                "name": "choices.opt4",
                "label": "Option 4",
                "defaultChecked": false,
                "disabled": false,
                "onChangeAction": {
                  "type": "choices.toggle",
                  "payload": {
                    "id": "opt4"
                  }
                }
              }
            ]
          },
          {
            "type": "ListViewItem",
            "key": "opt5",
            "align": "center",
            "children": [
              {
                "type": "Checkbox",
                "name": "choices.opt5",
                "label": "Option 5",
                "defaultChecked": false,
                "disabled": false,
                "onChangeAction": {
                  "type": "choices.toggle",
                  "payload": {
                    "id": "opt5"
                  }
                }
              }
            ]
          },
          {
            "type": "ListViewItem",
            "key": "opt6",
            "align": "center",
            "children": [
              {
                "type": "Checkbox",
                "name": "choices.opt6",
                "label": "Option 6",
                "defaultChecked": false,
                "disabled": false,
                "onChangeAction": {
                  "type": "choices.toggle",
                  "payload": {
                    "id": "opt6"
                  }
                }
              }
            ]
          }
        ]
      }
    ]
  },
  "encodedWidget": "eyJpZCI6ImMxNWY5NDY1LTY0MGMtNDg2NS04NDUzLWU3ZGE0ZjZkZGQyMiIsIm5hbWUiOiJNdWx0aS1jaG9pY2UgU2VsZWN0b3IiLCJ2aWV3IjoiPENhcmRcbiAgYXNGb3JtXG4gIHNpemU9XCJtZFwiXG4gIGNvbmZpcm09e3tcbiAgICBsYWJlbDogXCJEb25lXCIsXG4gICAgYWN0aW9uOiB7IHR5cGU6IFwiY2hvaWNlcy5zdWJtaXRcIiwgcGF5bG9hZDogeyBtYXg6IG1heFNlbGVjdGlvbnMgfSB9LFxuICB9fVxuPlxuICA8Q29sIGdhcD17Mn0-XG4gICAgPFRpdGxlIHZhbHVlPXt0aXRsZX0gc2l6ZT1cInNtXCIgLz5cbiAgICA8Um93PlxuICAgICAgPENhcHRpb24gdmFsdWU9e2BTZWxlY3QgdXAgdG8gJHttYXhTZWxlY3Rpb25zfWB9IC8-XG4gICAgICA8U3BhY2VyIC8-XG4gICAgICA8Q2FwdGlvblxuICAgICAgICB2YWx1ZT17YCR7c2VsZWN0ZWRDb3VudH0vJHttYXhTZWxlY3Rpb25zfSBzZWxlY3RlZGB9XG4gICAgICAgIGNvbG9yPVwiZW1waGFzaXNcIlxuICAgICAgLz5cb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