AdaptiveCards icon indicating copy to clipboard operation
AdaptiveCards copied to clipboard

[Input validation] Allow all input values to be included in Action.Submit, even if not associated

Open dclaux opened this issue 4 years ago • 4 comments

Platforms

  • [ ] .NET HTML
  • [ ] .NET WPF
  • [ ] Android
  • [ ] iOS
  • [ ] JavaScript
  • [ ] UWP

Problems

  • P0: When an Action.Submit's associatedInputs property is set to "none", not only are inputs not validated, their values are also not included in the data property. While this is the desired behavior in most cases, some scenarios call for all input values being included in data even though some or all of those inputs are not validated.
  • P1: associatedInputs should allow for more granularity in terms of which inputs are associated
  • P2: There should be a way to granularly specify which input values should be included in the data property of an Action.Submit

Proposed solutions

IMPORTANT: The below only refers to Action.Submit, but all of the proposed changes also apply to Action.Execute when we introduce it.

P0: Include all input values in data

We will introduce a new includedInputValues property on Action.Submit. Valid values will be "associated" (default) and "all".

  • By default, or when includedInputValues is set to "associated", the current behavior will be maintained (e.g. only the values of the inputs identified via the associatedInputs property are serialized into the data object).
  • When includedInputValues is set to "all", the values of all the inputs in the card are include in the data object

Example

With the below payload, the value of the text input is never included in the data property of the Action.Submit, because its associatedInputs property is set to "none":

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3",
    "body": [
        {
            "type": "Input.Text",
            "placeholder": "Placeholder text",
            "id": "a",
            "label": "Text input"
        }
    ],
    "actions": [
        {
            "type": "Action.Submit",
            "title": "Submit",
            "associatedInputs": "none"
        }
    ]
}

To fix that using the proposal detailed above, a card author can add the includedInputValues property to the Action.Submit:

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3",
    "body": [
        {
            "type": "Input.Text",
            "placeholder": "Placeholder text",
            "id": "a",
            "label": "Text input"
        }
    ],
    "actions": [
        {
            "type": "Action.Submit",
            "title": "Submit",
            "associatedInputs": "none"
            "includedInputValues": "all"
        }
    ]
}

P1: Allow card authors to specify exactly which inputs should be validated

We extend the associatedInputs property to accept an array of strings, with each element representing an input Id. Only the inputs specified in the array are validated.

Rules:

  • If an Id doesn't map to any input, it is ignored
  • An empty array is equivalent to "none"

Example

In the card below, only input "a" is validated by the Action.Submit even though input "a" is marked as required:

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3",
    "body": [
        {
            "type": "Input.Text",
            "placeholder": "Placeholder text",
            "id": "a",
            "isRequired": true,
            "label": "Required, validated:"
        },
        {
            "type": "Input.Text",
            "placeholder": "Placeholder text",
            "id": "b",
            "isRequired": true,
            "label": "Required, NOT validated:"
        }
    ],
    "actions": [
        {
            "type": "Action.Submit",
            "title": "Submit",
            "associatedInputs": [ "a" ]
        }
    ]
}

P2: Allow card authors to specify exactly which input values should be included in data

We extend the proposed submissionInputs property to also accept "associated" to denote "include the values of the associated inputs", or an array of strings, with each item representing an input Id. Only the values of the inputs mentioned in the array are serialized to the data object.

Rules:

  • If an Id doesn't map to any input, it is ignored
  • An empty array forces no values to be serialized to the data object
  • If the property is omitted, it defaults to associated

Example:

In the cars below, only input "b" is validated, however the values of both inputs "a" and "b" are serialized into the data object of the Action.Submit:

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3",
    "body": [
        {
            "type": "Input.Text",
            "placeholder": "Placeholder text",
            "id": "a",
            "isRequired": true,
            "label": "Input 1:"
        },
        {
            "type": "Input.Text",
            "placeholder": "Placeholder text",
            "id": "b",
            "isRequired": true,
            "label": "Input 2:"
        }
    ],
    "actions": [
        {
            "type": "Action.Submit",
            "title": "Submit",
            "associatedInputs": [ "b" ],
            "submissionInputs": [ "a", "b" ]
        }
    ]
}

dclaux avatar Feb 16 '21 19:02 dclaux

@RebeccaAnne this looks great, thanks - I didn't scroll down all the way to P2 when I looked at this yesterday. Excited to see this hopefully come to fruition.

HiltonGiesenow avatar Mar 12 '21 07:03 HiltonGiesenow

That's a great feature! I hope that this will be implemented soon

MassiveTM avatar Oct 17 '22 16:10 MassiveTM

I could really use something like this now. In the pertinent scenario, we want to be able to validate when attempting to 'save' values, but not when we want to refresh some data values that populate dropdowns on the card. In other words, there are some scenarios where a user has partially completed form inputs and we need to make a postback. In this scenario, we essentially want to be able to temporarily know/save the user input values during a postback and then use those values to rehydrate the response so the user does not lose their progress in completing the form.

paul-schroeder-msft avatar Oct 03 '23 19:10 paul-schroeder-msft

Is there any update on when this might make it's way into the production version?

jwccit avatar Apr 19 '24 09:04 jwccit