微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 当用户将字段名称作为值提交时,FormFlow禁用字段之间的切换

我们在我们的机器人中使用FormFlow. FormFlow有一个功能,允许用户键入字段的名称,并切换到给定的字段.假设我们有这样的模型类

public class SampleModelClass
    {
        public string FirstField { get; set; }
        public string SecondField { get; set; }
    }

当要求用户输入FirstField时,用户可能实际输入“first field”,这导致再次询问FirstField的问题.有没有办法禁用它并将“first field”作为FirstField的值?重命名FirstField会起作用,但我们正在寻找更好的解决方

解决方法

When the user is asked to enter FirstField there is a possibility that the user can actually type “first field” which results in asking the question for the FirstField again. Is there any way to disable this and take “first field” as the value of FirstField? Renaming FirstField would work,but we are looking for a better solution

您可以尝试使用Terms attribute(使用正则表达式)来定义用于将用户输入与字段或字段中的值匹配的术语列表,以下示例供您参考.

[Serializable]
public class SampleModelClass
{
    [Terms(@"^[.*]$")]
    public string FirstField { get; set; }

    [Terms(@"^[.*]$")]
    public string SecondField { get; set; }

    public static IForm<SampleModelClass> BuildForm()
    {
        return new FormBuilder<SampleModelClass>()
                .Message(async (state) => { return new PromptAttribute($"Welcome to the form bot!"); })
                .Build();


    }
}

测试结果:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐