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

FormFlow disable switching between fields when user submits field name as value

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

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


    }
}

测试结果: