0

I have the following simple card:

    {
        "type": "AdaptiveCard",
        "version": "1.0",
        "body": [
            {
                "type": "TextBlock",
                "text": "{data}"
            }
        ],
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
    }

When I apply the following data to the card (value is number), the text box is empty:

{
"data":11111
}

With text, the I can see the data in the card:

{
"data":"11111"
}

This is not a code issue, this is how it looks in the designer. Am I missing something, is there a type for a text box that lets display numbers or is this by design and I have to change all numeric fields to text?

vilmarci
  • 451
  • 10
  • 31

3 Answers3

1

This is a limitation of the preview (known as Type Coercion) that we hope to address before release. As another workaround you can include a space after the binding expression which will force it into a string. See the below example, notice the space after {data}


   {
        "type": "AdaptiveCard",
        "version": "1.0",
        "body": [
            {
                "type": "TextBlock",
                "text": "{data} "
            }
        ],
        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
    }
Matt Hidinger
  • 1,743
  • 16
  • 16
0

I'm guessing you're using Adaptive Cards Templating for this. Remember, this is (a) in preview only and (b) just one option for constructing an Adaptive Card. Basically, at the end of the day, the Card is just a string of JSON text so you can create it in 3 main ways:

  1. Using Templates, as you're doing now
  2. Doing string replacement of your own (e.g. var card = '..."text": "##Number##"...' and then card = card.Replace("##Number##", formattedNumberValue)
  3. Using strongly-typed options like the AdaptiveCards Nuget package for C#, for instance

So, I'd suggest, if this is not possible using Templating, to look more at options 2 or 3 above. I described this a bit more here, with some links to C# and Node examples.

Hope that helps

Hilton Giesenow
  • 9,809
  • 2
  • 10
  • 24
  • Well, right now, I am only building the card with designer at https://adaptivecards.io/designer/ so, I guess, that is using templating behind the scenes. – vilmarci Jan 09 '20 at 13:24
  • Ahh ok, I see. Yeah, seems to be a restriction in the new Templating, but if you start using it in an actual project you could use one of the other approaches I suggested, even if it's just in the interim till Templates gets to V1. – Hilton Giesenow Jan 09 '20 at 15:11
0

You can now use the function formatNumber(value, decimalplaces)

Eg:

{
  "type": "TextBlock",
  "text": "${formatNumber(somenumber), 2}"
}

You can read mode here: https://learn.microsoft.com/en-us/azure/bot-service/adaptive-expressions/adaptive-expressions-prebuilt-functions?view=azure-bot-service-4.0#formatNumber

BJury
  • 2,526
  • 3
  • 16
  • 27