Skip to main content

How to Set a Minimum and Maximum on an Adaptive Card Number Input

· 5 min read
Jagdish Kumawat
Founder @ Dewiride

Quantities, ages, people per room: many card fields want a number within limits. An Adaptive Card Input.Number takes a min and a max, and in Microsoft Teams, the box keeps every number inside them.

Syntax​

Card JSON
{
"type": "Input.Number",
"id": "<input id>",
"label": "<label>",
"min": <lowest number>,
"max": <highest number>,
"value": <starting number>,
"errorMessage": "<what to show when the number is wrong>"
}
PartWhat it does
minHint of minimum value (may be ignored by some clients).
maxHint of maximum value (may be ignored by some clients).
valueInitial value for this field.
errorMessageError message to display when entered input is invalid

The descriptions are from Microsoft's Input.Number reference. Hint matters: each app that shows the card decides how to keep to the range. The Input Validation guide says what can happen: Min and max properties (including maxLength) on some platforms may be enforced directly by the control. ... In that case, the error message may not be shown.

The Example​

A concert ticket card allows 1 to 4 tickets, starts at 1, and says the range in its label, Tickets (1 to 4).

Prerequisites​

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

Step 1: Write the Card​

Cards/tickets.json
{
"type": "AdaptiveCard",
"version": "1.5",
"body": [
{ "type": "TextBlock", "text": "Concert tickets", "size": "Large", "weight": "Bolder" },
{
"type": "Input.Number",
"id": "tickets",
"label": "Tickets (1 to 4)",
"min": 1,
"max": 4,
"value": 1,
"errorMessage": "Pick from 1 to 4 tickets."
}
],
"actions": [
{ "type": "Action.Submit", "title": "Buy", "data": { "card": "tickets" } }
]
}

tickets.json in a macOS-style editor window: an Adaptive Card with a Concert tickets title, an Input.Number with id tickets, label Tickets (1 to 4), min 1, max 4, value 1 and an errorMessage, and a Buy button

min, max and value are numbers in the JSON, without quotes.

Step 2: Try a Number Below the Minimum​

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

The Concert tickets card in Teams: Tickets (1 to 4) above a number box holding 1, with up and down arrows, and a Buy button

Type 0:

The same card with 0 typed in the focused number box

Then select the card's title, to leave the box:

The same card after leaving the box: it shows 1 again, with no error message

Teams changed 0 to 1, the minimum, without a message. A number above the maximum goes to the maximum the same way.

Step 3: Buy​

Type 2, and select Buy. The agent for this post replies with the values it receives:

The card with 2 in the box and Teams' note Your response was sent to the app, and below it the agent's reply The card sent: card tickets, tickets 2

What the agent received
{"card":"tickets","tickets":"2"}

The number arrived as text, "2". Parse it before you calculate with it, for example with int.TryParse in C#.

Common Mistakes​

MistakeWhat happensDo this instead
Counting on errorMessage to explain the rangeIn Teams, the box changes the number instead, with no messageSay the range in the label
Trusting min and max aloneThey're hints, and other apps may not enforce themCheck the number in the agent too

Troubleshooting​

SymptomLikely causeFix
A typed number changes when you leave the boxTeams moves it into the rangeExpected: the box shows what will be sent
The agent can't do math with the valueIt's text, such as "2"Parse it first

FAQ​

Why didn't the error message show for 6 on a 1-to-4 box?​

Because Teams changed it to 4 when the box lost focus, so nothing was out of range when the card checked: Fixed: An Adaptive Card Number Input in Teams Changes to Its Maximum Instead of Showing the Error Message follows that one through.

How do I make the number required?​

Add "isRequired": true, with the errorMessage: How to Make Adaptive Card Inputs Required.

Conclusion​

Give an Input.Number a min, a max and a starting value, and say the range in its label. Teams keeps the number inside the range by itself, and the card sends it as text, so your agent parses it and checks it once more.

Additional Resources​