仅在更改提示中隐藏 "No Preference" 按钮
Hide "No Preference" button only in the change prompt
我只想删除表单流中 "Change prompt" 中的 "No Preference" 或至少更改它的文本,以便仅在确认提示中保留带有 "No Preference" 选项的表单.
我可以更改它的文本,但它更改了整个表格并且对我不起作用。
public static IForm<PromoBot> BuildForm()
var form = new FormBuilder<PromoBot>()
.Message("Hi......!")
.Field(nameof(Nome), validate: async (state, value) =>
{
..........
result.IsValid = true;
return result;
}, active: state => true)
.Message("xxxxxx")
.Field(nameof(CEP)
.Field(nameof(Estados))
.Confirm(async (state) =>
{
return new PromptAttribute("You have selected the following: \n {*} "Is this correct?{||}");
})
.Message("Excelente! Agora vou precisar de alguns segundos para encontrar o melhor plano para sua empresa… já volto!")
.OnCompletion(OnComplete);
var noPreferenceStrings = new string[] { "New Text" };
form.Configuration.Templates.Single(t => t.Usage == TemplateUsage.NoPreference).Patterns = noPreferenceStrings;
form.Configuration.NoPreference = noPreferenceStrings;
return form.Build();
}
通常您可以使用模板属性来修改 FormFlow 的行为,但导航步骤有点挑剔。我认为在这种情况下最好的办法是为您的表格提供 custom prompter.
在您的情况下,代码可能如下所示:
public static IForm<MyClass> BuildForm()
{
var formBuilder = new FormBuilder<MyClass>()
.Field(nameof(FirstName))
.Field(nameof(LastName))
.Confirm("Is this okay? {*}")
.Prompter(PromptAsync)
;
return formBuilder.Build();
}
/// <summary>
/// Here is the method we're using for the PromptAsyncDelgate.
/// </summary>
private static async Task<FormPrompt> PromptAsync(IDialogContext context, FormPrompt prompt,
MyClass state, IField<MyClass> field)
{
var preamble = context.MakeMessage();
var promptMessage = context.MakeMessage();
// Check to see if the form is on the navigation step
if (field.Name.Contains("navigate") && prompt.Buttons.Any())
{
// If it's on the navigation step,
// we want to change or remove the No Preference line
if (you_want_to_change_it)
{
var noPreferenceButton = prompt.Buttons.Last();
// Make sure the Message stays the same or else
// FormFlow won't know what to do when this button is clicked
noPreferenceButton.Message = noPreferenceButton.Description;
noPreferenceButton.Description = "Back";
}
else if(you_want_to_remove_it)
{
prompt.Buttons.RemoveAt(prompt.Buttons.Count - 1);
}
}
if (prompt.GenerateMessages(preamble, promptMessage))
{
await context.PostAsync(preamble);
}
await context.PostAsync(promptMessage);
return prompt;
}
补充说明:"Back"实际上是FormFlow中的一个特殊命令。 "No Preference" 将带您返回确认步骤,而 "Back" 将带您到表单中的最后一个字段。如果你真的想在你的导航步骤中放置一个后退按钮,你可以省略这一行:
noPreferenceButton.Message = noPreferenceButton.Description;
我只想删除表单流中 "Change prompt" 中的 "No Preference" 或至少更改它的文本,以便仅在确认提示中保留带有 "No Preference" 选项的表单.
我可以更改它的文本,但它更改了整个表格并且对我不起作用。
public static IForm<PromoBot> BuildForm()
var form = new FormBuilder<PromoBot>()
.Message("Hi......!")
.Field(nameof(Nome), validate: async (state, value) =>
{
..........
result.IsValid = true;
return result;
}, active: state => true)
.Message("xxxxxx")
.Field(nameof(CEP)
.Field(nameof(Estados))
.Confirm(async (state) =>
{
return new PromptAttribute("You have selected the following: \n {*} "Is this correct?{||}");
})
.Message("Excelente! Agora vou precisar de alguns segundos para encontrar o melhor plano para sua empresa… já volto!")
.OnCompletion(OnComplete);
var noPreferenceStrings = new string[] { "New Text" };
form.Configuration.Templates.Single(t => t.Usage == TemplateUsage.NoPreference).Patterns = noPreferenceStrings;
form.Configuration.NoPreference = noPreferenceStrings;
return form.Build();
}
通常您可以使用模板属性来修改 FormFlow 的行为,但导航步骤有点挑剔。我认为在这种情况下最好的办法是为您的表格提供 custom prompter.
在您的情况下,代码可能如下所示:
public static IForm<MyClass> BuildForm()
{
var formBuilder = new FormBuilder<MyClass>()
.Field(nameof(FirstName))
.Field(nameof(LastName))
.Confirm("Is this okay? {*}")
.Prompter(PromptAsync)
;
return formBuilder.Build();
}
/// <summary>
/// Here is the method we're using for the PromptAsyncDelgate.
/// </summary>
private static async Task<FormPrompt> PromptAsync(IDialogContext context, FormPrompt prompt,
MyClass state, IField<MyClass> field)
{
var preamble = context.MakeMessage();
var promptMessage = context.MakeMessage();
// Check to see if the form is on the navigation step
if (field.Name.Contains("navigate") && prompt.Buttons.Any())
{
// If it's on the navigation step,
// we want to change or remove the No Preference line
if (you_want_to_change_it)
{
var noPreferenceButton = prompt.Buttons.Last();
// Make sure the Message stays the same or else
// FormFlow won't know what to do when this button is clicked
noPreferenceButton.Message = noPreferenceButton.Description;
noPreferenceButton.Description = "Back";
}
else if(you_want_to_remove_it)
{
prompt.Buttons.RemoveAt(prompt.Buttons.Count - 1);
}
}
if (prompt.GenerateMessages(preamble, promptMessage))
{
await context.PostAsync(preamble);
}
await context.PostAsync(promptMessage);
return prompt;
}
补充说明:"Back"实际上是FormFlow中的一个特殊命令。 "No Preference" 将带您返回确认步骤,而 "Back" 将带您到表单中的最后一个字段。如果你真的想在你的导航步骤中放置一个后退按钮,你可以省略这一行:
noPreferenceButton.Message = noPreferenceButton.Description;