我有一个表单流对话框,其中一个属性是这个......
[Describe("Car Mileage")]
[Prompt("Cool! What's the mileage of the car?")]
[Template(TemplateUsage.NotUnderstood, "Sorry, I didn't understand that mileage value. Can you enter it again please?")]
public string Mileage { get; set; }
暂时忽略[Template(TemplateUsage.NotUnderstood,...,我会回到那个。
该对话框是使用以下内容构建的...
var form = builder
.Field(new FieldReflector<CarValuationDialog>(nameof(ValuationOption))
.SetPrompt(new PromptAttribute($"Hi.<br /><br />Are you looking to get a value for a car you're selling, or car you're buying? {{||}}")))
.Field(new FieldReflector<CarValuationDialog>(nameof(RegistrationNumber))
.SetDefine(RegistrationNumberDefinitionMethod))
.Field(new FieldReflector<CarValuationDialog>(nameof(Mileage))
.SetValidate(async (state, value) =>
{
var result = new ValidateResult { IsValid = true, Value = value };
var regex = new Regex("[0-9,]+");
var match = regex.Match((string)value);
if (match.Success)
{
result.IsValid = true;
}
else
{
result.Feedback = "Sorry, I didn't understand that.";
result.IsValid = false;
}
return await Task.FromResult(result);
}))
.Field(
nameof(PreviousOwnerOption),
active: carValuationDialog => carValuationDialog.ValuationOption == ValuationOptions.LookingToSell)
.Field(
nameof(ServiceHistoryOption),
active: carValuationDialog => carValuationDialog.ValuationOption == ValuationOptions.LookingToSell)
.Confirm(Confirmation)
.OnCompletion(GetValuationAndDisplaySummaryToUser);
return form.Build();
这个问题与
我正在尝试验证Mileage,因为我已将该属性从 更改int为string以允许自由流动文本,例如“23,456 英里”。作为更改数据类型的副作用,当验证Mileage失败时,我得到以下...
现在不仅会result.Feedback向用户显示该值(以前没有,什么时候Mileage是int),这很好,而且还会显示原始问题文本。
所以我的主要问题是 - 我该怎么做才能在验证失败时不向用户显示原始问题提示?
附带说明,当更改Mileage回 时int,验证失败 ( result.IsValid = false)result.Feedback未显示,但[Template(TemplateUsage.NotUndderstood....现在显示。因此,似乎属性的类型与显示的验证消息有关。
