简体   繁体   中英

Showing Datepicker in FormFlow (Bot Framework)

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();
        }
    }

在此处输入图片说明

Can we show datepicker instead?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM