简体   繁体   中英

Proper Adaptive Card Input.ChoiceSet Templating Structure

What does the data json need to be to set a choice as selected on an Input.ChoiceSet?

Card Json

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "Input.ChoiceSet",
            "placeholder": "Placeholder text",
            "choices": [
                {
                    "title": "Choice 1",
                    "value": "1"
                },
                {
                    "title": "Choice 2",
                    "value": "2"
                }
            ],
            "style": "expanded",
            "id": "sample"
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.0"
}

Sample Data Json

What should the structure of this be if I wanted to set the value of Choice 1 to selected?

{
    // I've tried this:
    "sample": {
        "value": "1"
    }
}
-----------------------------
{
    // Also tried
    "sample": "1"
}

I'm reading the Adaptive Card schema for Input.ChoiceSet and I see that the card json "value": property can be set in the card for default values, but I'm hoping there is a way to do this from the template json. Otherwise, I'll have to "inject" it into the card json before I build the card.

based on your sample there you have to do this:

            [...]
            "placeholder": "Placeholder text",
            "value": 1,
            "choices": [
                {
                    "title": "Choice 1",
                    "value": "1"
                },
             [...]

To set the initial value, based on one of the values in your choices array. It only works if the corresponding value is exactly the same for one of the entries. There is nothing like "selected: true" or similar if that's what you're asking for.

When using templating for that, you would have to have a selected property returned and set it as "value": {$root.selected}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM