加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 22:52:07 所属栏目:百科 来源:网络整理
导读:我们在我们的机器人中使用FormFlow. FormFlow有一个功能,允许用户键入字段的名称,并切换到给定的字段.假设我们有这样的模型类 public class SampleModelClass { public string FirstField { get; set; } public string SecondField { get; set; } } 当要求用
我们在我们的机器人中使用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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读