在SetValidate调用中设置对话框属性值不起作用

时间:2018-06-29 09:16:59

标签: botframework

给出以下表单流程设置...

return builder
    .Field(new FieldReflector<CarValuationDialog>(nameof(Mileage))
        .SetValidate(async (state, value) =>
            {
                var result = new ValidateResult { IsValid = true };

                if (int.TryParse(value.ToString(), out int mileage))
                {
                    state.Mileage = mileage;
                    result.IsValid = true;
                }
                else
                {
                    result.Feedback = "That isn't valid number. Can you enter it again please?";
                    result.IsValid = false;
                }

                return result;
            }))

    .Field(new FieldReflector<CarValuationDialog>(nameof(HappyWithAnswersBuying))
        .SetActive(carValuationDialog => carValuationDialog.ValuationOption == ValuationOptions.LookingToOwn)
        .SetPrompt(CreateHappyWithAnswersBuyingPrompt())
        .SetDefine(HappyWithAnswersDefinitionMethod))
    .OnCompletion(GetValuationAndDisplaySummaryToUser)
    .Build();

我想尝试对用户给出的里程答案进行自定义验证。执行SetValidate中的代码,并指定一个有效的整数,将该数字分配给state.Mileage

但是,当显示询问用户是否对答案满意的提示时,里程数仍设置为0。

enter image description here

这是提示的代码。

private static PromptAttribute CreateHappyWithAnswersBuyingPrompt()
{
    StringBuilder sb = new StringBuilder(100);

    sb.Append("Are you happy with your answers? <br /><br />");
    sb.Append("{&RegistrationNumber}: {RegistrationNumber} <br />");
    sb.Append("{&Mileage}: {Mileage:N0} miles {||}");

    return new PromptAttribute(sb.ToString())
    {
        ChoiceStyle = ChoiceStyleOptions.Buttons,
        FieldCase = CaseNormalization.InitialUpper
    };
}

在添加SetValidate代码之前,里程在提示中显示的很好。但是,由于我现在手动设置state.Mileage,因此由于某种原因它不会一直存在。

1 个答案:

答案 0 :(得分:0)

老兄,我非常需要在代码中“检查插头” ...

基本上我没有设置Value实例的ValidateResult属性...

.SetValidate(async (state, value) =>
{
    var result = new ValidateResult { IsValid = true, Value = value };

    ....
}

这样做之后,里程值现在显示在提示中...

enter image description here