简体   繁体   中英

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

We are using FormFlow in our bot. FormFlow has a feature that allows a user to type the name of the field and it switches to the given field. Let's say we have a model class like this

    public class SampleModelClass
    {
        public string FirstField { get; set; }
        public string SecondField { get; set; }
    }

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

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

You can try to use the Terms attribute (with a regular expression) to define the list of terms that are used to match user input to a field or a value in a field, the following sample is for your reference.

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


    }
}

Test result:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM