Akshay Akshay - 4 months ago 68
C# Question

Can form flow fields in bot framework be pre-populated?

I have used formflow to ask several questions and to finally fill up a form. A unique id is generated and given to user at the end. Now using that unique id I want to edit the form. Is it possible to pre-populate the fields? Or is there any other way to do so?

This is the code that I am using to create a form for first time:

public static IForm<AssesmentHelper> BuildForm()
OnCompletionAsyncDelegate<AssesmentHelper> wrapUpRequest = async (context, state) =>
//Do something....

return new FormBuilder<AssesmentHelper>()
.Field(nameof(Email), validate: ValidateMailId)

Now, I want to pre-populate fields (Name, Age, Address) so that I can use it for editing as well.


Yes, you can pass an instance of your Form state/model to the FormDialog with the Form parameters pre-filled (as you can see here). Have in mind that . if you do that, any step for filling a field is skipped if that field has a value.

If you still want to ask for those parameters even if they have a value; you must change the FormOptions and use FormOptions.PromptFieldsWithValues, which will prompt for fields, but use the passed in state for defaults.

The relevant docs for this are here.