Regarding the submit button in adaptive cards

Viewed 489

My question is regarding the submit button in adaptive cards. I'm implementing an adaptive card for the date of birth in of the records. Till now, I have implemented a date picker where the default value of the date picker will be the user's DOB present in the records. I need to disable to the "Update" button until/unless the user changes the default value. Is it possible to implement the date picker in this manner? I'm attaching the screen shot of the date picker that I've implemented till now. Thanks in advance.

Image

public static Attachment DatePickerAttachment(string givenDob, string maxDate, string minDate)
            {
                var card = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2));

                card.Body.Add(new AdaptiveTextBlock()
                {
                    Text = $"Please enter the date",
                    Wrap = true,
                    Size = AdaptiveTextSize.Default,
                    Spacing = AdaptiveSpacing.Medium
                });

                var inputDate = new AdaptiveDateInput()
                {
                    Id = "date",
                    Placeholder = "Please enter the date",
                    Value = $"{givenDob}",
                    Max = $"{maxDate}",
                    Min = $"{minDate}"
                };

                card.Body.Add(inputDate);

                var dataObj = new SimpleObjClass()
                {
                    value = "go on with the process"
                };

                var action = new AdaptiveSubmitAction()
                {
                    Title = "Update",
                    Data = dataObj,
                };
                card.Actions.Add(action);



                var dataObj2 = new SimpleObjClass() { value = "kill the process" };
                var action1 = new AdaptiveSubmitAction()
                {
                    Title = "Cancel",
                    Data = dataObj2,
                };
                card.Actions.Add(action1);

                var attachment = new Attachment
                {
                    ContentType = AdaptiveCard.ContentType,
                    Content = JsonConvert.DeserializeObject(JsonConvert.SerializeObject(card)),
                };
                return attachment;
            }

1 Answers

Looking at the image, it looks like you are using the Web Chat channel. I believe the 1.3 schema is supported, which means you could look to use the native validation in the Adaptive Card, specifically the "isRequired" and "errorMessage" properties.

{
    "type": "AdaptiveCard",
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.3",
    "body": [
        {
            "type": "Input.Date",
            "isRequired": true,
            "errorMessage": "Please select a date",
            "id": "Date",
            "label": "Date",
            "value": "10/10/2020"
        }
    ],
    "actions": [
        {
            "type": "Action.Submit",
            "title": "Update"
        }
    ]
}

Adaptive card demo

Related