Showing Datepicker in FormFlow (Bot Framework)

我是研究僧i 提交于 2019-12-23 04:55:33

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/48018054/showing-datepicker-in-formflow-bot-framework

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!