我们在我们的机器人中使用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();
}
}
测试结果: