Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JS] Only enable action buttons when their associated inputs have changed #7104

Merged
merged 8 commits into from
Mar 17, 2022

Conversation

dclaux
Copy link
Member

@dclaux dclaux commented Mar 9, 2022

Related Issue

Implements #7103

Description

This change adds support for disabling action buttons unless their associated inputs have changed

  • Adds a CardElement.getAllActions method that makes it easy to retrieve a list of all actions in the card
  • Adds a CardElement.updateActionsEnabledState that refreshes the visual state of all actions in the card
  • Adds the Action.disabledUnlessAssociatedInputsChange: boolean property on Action
    • Add support for that property in the designer
  • Changes the logic for a button to be disabled if its isEnabled property is set to false OR if none of its associated inputs have changed
  • Adds a SubmitActionBase.updateEnabledState method that refreshes the visual state of an action button according to the current values of its associated inputs
  • Adds a SubmitActionBase.resetReferencedInputsDirtyState method that allows a host app to indicate that an action's associated inputs are not "dirty" anymore, i.e. their values are current (and the action should therefore be disabled)
  • Adds the GlobalSettings.resetInputsDirtyStateAfterActionExecution: boolean flag that allows a host application to disable the automatic reset of inputs' dirty state after an action button has been clicked

Sample Card

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.6",
    "body": [
        {
            "type": "Input.Text",
            "placeholder": "Placeholder text",
            "id": "abc",
            "label": "Enter some text:"
        },
        {
            "type": "Input.ChoiceSet",
            "choices": [
                {
                    "title": "Choice 1",
                    "value": "Choice 1"
                },
                {
                    "title": "Choice 2",
                    "value": "Choice 2"
                }
            ],
            "placeholder": "Placeholder text",
            "id": "def",
            "label": "Make a choice:"
        }
    ],
    "actions": [
        {
            "type": "Action.Execute",
            "title": "Save",
            "disabledUnlessAssociatedInputsChange": true
        }
    ]
}

Initial render:
image

After the user has updated at least one input:
image

How verified

Verified manually in adaptivecards-designer-app

Microsoft Reviewers: Open in CodeFlow

@ghost
Copy link

ghost commented Mar 9, 2022

Hi @dclaux. Thanks for helping make the AdaptiveCards JS renderer + tooling better. As additional verification, once the JS build succeeds, please go to the test site to test out your website/designer changes.

Copy link
Contributor

@licanhua licanhua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me. I prefer const over let in some places, but it's not a blocker for this PR

source/nodejs/adaptivecards/src/card-elements.ts Outdated Show resolved Hide resolved
source/nodejs/adaptivecards/src/card-elements.ts Outdated Show resolved Hide resolved
source/nodejs/adaptivecards/src/card-elements.ts Outdated Show resolved Hide resolved
@beervoley beervoley merged commit c5047d7 into microsoft:main Mar 17, 2022
michaelfarnsworth pushed a commit to michaelfarnsworth/AdaptiveCards that referenced this pull request Nov 10, 2022
…nged (microsoft#7104)

* Introduce getAllActions Replace concat with push for perf

* Disable actions unless input values change
Reformat certain things back to how they used to be

* Address review feedback so far

* Fix flawed isEnabled behavior

* let -> const

Co-authored-by: Vsevolod <sevkorobot@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants