microsoft / AdaptiveCards

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

Action.ToggleVisibility does not trigger an onAction event #8711

Closed aboultonhumana closed 8 months ago

aboultonhumana commented 8 months ago

Target Application

Viva Connections Dashboard

Application Operating System

Windows

Schema Version

1.5

Problem Description

Setting an action of Action.ToggleVisibility in the Quick View JSON does not trigger the onAction event in SPFx code.

Expected Outcome

Expecting the Action.ToggleVisibility action to trigger an onAction even in the same way that Action.Submit and Action.Execute trigger the event.

Actual Outcome

onAction event is not triggered.

Card JSON

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.5",
    "body": [
        {
            "type": "ActionSet",
            "actions": [
                {
                    "type": "Action.ToggleVisibility",
                    "title": "Toggle visibility",
                    "id": "ToggleButton",
                    "targetElements": [
                        "hidden"
                    ]
                }
            ]
        },
        {
            "type": "TextBlock",
            "text": "Initially hidden content",
            "wrap": true,
            "id": "hidden",
            "isVisible": false
        }
    ]
}

Repro Steps

jwoo-msft commented 8 months ago

@aboultonhumana,

Have you tried using your JSON in the designer? I didn't find any issues there. I'm closing this issue. Please respond to this thread if you have any further questions.

aboultonhumana commented 8 months ago

@aboultonhumana,

Have you tried using your JSON in the designer? I didn't find any issues there. I'm closing this issue. Please respond to this thread if you have any further questions.

Correct, Action.ToggleVisibility triggers the action event (i.e. pops up the alert with the data) in the Designer tool but not in SharePoint Framework (v 1.18 and tested with earlier versions). The other universal actions do trigger the event in code.

jwoo-msft commented 8 months ago

@aboultonhumana, Have you spoken with the developers who maintain SharePoint Framework? As demonstrated, Adaptive Cards are functioning correctly, as the designer is running on the latest version of Adaptive Cards.

aboultonhumana commented 8 months ago

Thanks @jwoo-msft -- agreed it's an issue with the SPFx implementation. For anyone stumbling upon this, a workaround is to not use the ToggleVisibility action, but instead to use Action.Execute in combination with the $when attribute in the JSON template to show/hide the element based on a value stored in the card's state (e.g. a value of ${showTheThing} that is initially false). So, instead of setting a ToggleVisibility action on an element, use Action.Execute in combination with a verb used to identify that specific interaction. Then, for the Execute action, the onAction event handler in the SPFx ACE code is triggered. When that specific Action + verb occurs we then update the card's state corresponding to the $when condition, e.g. setting the showTheThing to true to conditionally show the element(s).