0
votes

I am working on a FormFlow feature of a bot framework in one of my bot projects. The bot is required to get input from user about the date range (From and To). The form flow works, however the bot requires to enter DateTime in string. To avoid human errors, I would like it to be a Date picker (like the one in Adaptive Cards) instead of string input from user.

I tried setting type of field explicitly but it didn't work for some reason. See the code below.

    [Serializable]
    public class Leave
    {
        [Prompt("Select type of leave you want to apply.")]
        public LeaveTypeEnum LeaveType;

        [Prompt("Vacations from date")]
        public DateTime? From;

        [Prompt("To date")]
        public DateTime? To;



        public static IForm<Leave> BuildForm()
        {
            return new FormBuilder<Leave>().Message
            ("Fill in the form.")
                .Field(new FieldReflector<Leave>(nameof(From)).SetType(typeof(DateTime)))
                .Field(nameof(From))
                .Field(nameof(To))
                .Build();
        }
    }

enter image description here

Can we show datepicker instead?

1

1 Answers

0
votes

The short answer is no, there is no DatePicker component in botframework.

Handle datetime inputs

You should instead be able to get a datetime by text from your user and handle many formats, by using Microsoft's Recognizers-Text GitHub project for example: https://github.com/Microsoft/Recognizers-Text

It is made for parsing text inputs in several types, and DateTime is one of the provided types. It is available in NuGet packages.