Skip to main content

How to Prefill the Inputs of an Adaptive Card

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

A form that changes something people already have, such as their contact details, should open with what's there now. Every Adaptive Card input has a value property for that: the card shows it, people change what they need, and Submit sends the rest as it was.

Syntax​

Card JSON
{ "type": "Input.Text", "id": "<input id>", "value": "<text>" }
{ "type": "Input.Number", "id": "<input id>", "value": <number> }
{ "type": "Input.ChoiceSet", "id": "<input id>", "value": "<a choice's value>", "choices": [ ... ] }
{ "type": "Input.Toggle", "id": "<input id>", "title": "<text>", "value": "<valueOn or valueOff>" }
Inputvalue is
Input.TextThe initial value for this field., as text
Input.NumberInitial value for this field., as a number
Input.ChoiceSetThe initial choice (or set of choices) that should be selected.: a choice's value, not its title
Input.ToggleThe initial selected value. On when it equals valueOn, which is "true" unless you set it

The descriptions are from Microsoft's Adaptive Cards schema. The Input.Toggle page puts it this way: If you want the toggle to be initially on, set this to the value of valueOn's value.

The Example​

A contact details card opens with a phone number, +1 555 0100, and a ticked Send me text messages toggle, and has a Save button.

Prerequisites​

  • An agent that sends Adaptive Cards in Microsoft Teams and reads what a card's Submit button sends.

Step 1: Write the Card with Values​

Cards/phone.json
{
"type": "AdaptiveCard",
"version": "1.5",
"body": [
{ "type": "TextBlock", "text": "Your contact details", "size": "Large", "weight": "Bolder" },
{ "type": "Input.Text", "id": "phone", "label": "Phone number", "value": "+1 555 0100" },
{ "type": "Input.Toggle", "id": "texts", "title": "Send me text messages", "value": "true" }
],
"actions": [
{ "type": "Action.Submit", "title": "Save", "data": { "card": "phone" } }
]
}

phone.json in a macOS-style editor window: an Adaptive Card with a Your contact details title, an Input.Text with id phone and value +1 555 0100, an Input.Toggle with id texts, title Send me text messages and value true, and a Save button

  • "value": "+1 555 0100" fills the text box.
  • "value": "true" turns the toggle on, because "true" is its valueOn.

Step 2: Open It in Teams​

Send the card from your agent, as How to Send an Adaptive Card in the Microsoft 365 Agents SDK in C# shows:

The Your contact details card in Teams: Phone number with +1 555 0100 in the box, a ticked Send me text messages checkbox, and a Save button

Both inputs open with their values. In Teams, the toggle shows as a checkbox.

Step 3: Save Without Changing Anything​

Select Save. The agent for this post replies with the values it receives:

The card with Teams' note Your response was sent to the app, and below it the agent's reply The card sent: card phone, phone +1 555 0100, texts true

What the agent received
{"card":"phone","phone":"+1 555 0100","texts":"true"}

The prefilled values went back as they were, as text: the toggle sent "true", its valueOn.

Common Mistakes​

MistakeWhat happensDo this instead
Setting a toggle's value to something other than its valueOn and expecting it onThe schema turns it on only for valueOn's valueUse the valueOn text, "true" by default
Expecting only changed fields backEvery input sends its value, changed or notCompare with the old values in the agent, if it matters

Troubleshooting​

SymptomLikely causeFix
The toggle opens offvalue isn't exactly valueOnUse the same text in both

FAQ​

How does the agent fill in the current values?​

It builds the card in code, or edits a JSON template, before sending it, putting each current value in value. Card values come back as text, and the schema's value for an Input.Number is a number, so parse it back first.

Can I prefill a form in a Teams dialog?​

Yes. The dialog's card is an Adaptive Card like any other, and its inputs take value the same way: How to Show an Error in a Teams Dialog in the Microsoft 365 Agents SDK in C# sends a form back with what was typed.

Conclusion​

To prefill an Adaptive Card, set each input's value: text for Input.Text, a number for Input.Number, a choice's value for Input.ChoiceSet, and the valueOn text for a toggle that should start on. Submit sends every value, changed or not.

Additional Resources​