microsoft / AdaptiveCards

A new way for developers to exchange card content in a common and consistent way.
https://adaptivecards.io
MIT License
1.76k stars 550 forks source link

[Feature Request] support template bool for rtl and other boolean properties. #6631

Closed licanhua closed 2 years ago

licanhua commented 3 years ago

Problem Statement

$ is not a valid usage in JSON, so it has problem to convert the template data to bool directly.

"rtl": ${bool($rtl)}

Proposed solution

Data binding works as expected as requested in this feature request. To see the correct usage, see 4350. Designer needs to be updated so that a serialization doesn't happen before template expansion because templates are stripped off if the expected type are not string.

Alternatives or Workarounds

No response

aarongustafson commented 2 years ago

Ditto for int() to be used with value, min, and max for number fields.

aarongustafson commented 2 years ago

Another way of thinking about this, if the parsing is too much of a challenge: Could you adjust the API of these fields that require boolean, integers, etc. to allow for equivalents as well. So, 3 == "3" or true == 'true' or even true == 1. Making the API more liberal in what it accepts (with guardrails of course) would make for a more robust solution overall and eliminate the need for this sort of value coercion in a template to begin with.

JeanRoca commented 2 years ago

Is this a regression? I'm not sure if this is a new feature request or a bug since this PR seems to address it: https://github.com/microsoft/AdaptiveCards/pull/4351

JeanRoca commented 2 years ago

See https://github.com/microsoft/AdaptiveCards/issues/4350 as well

aarongustafson commented 2 years ago

@JeanRoca Given the dates, I’m guessing it’s a regression. Not sure if it is extended to int(), but if it isn’t it should be.

jwoo-msft commented 2 years ago

I think this might be just Designer issue. let me try that. There will be a lot more issues filed if this doesn't work.

jwoo-msft commented 2 years ago

I verify that it does work in code.

jwoo-msft commented 2 years ago

I've updated the feature request with a proposed solution.

JeanRoca commented 2 years ago

This also happens when trying to set image height and width using the data payload. You can only see the image change size when you hit preview mode. Is this expected behavior?

Card JSON

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.5",
    "body": [
        {
            "type": "TextBlock",
            "text": "Image test:",
            "wrap": true
        },
        {
            "type": "Image",
            "url": "https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg",
            "width": "${imageSize}",
            "height": "${imageSize}"
        }
    ]
}

Data JSON

{
    "imageSize": "100px"
}