问题
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>()
.Message(Responses.NumberSelection)
.Field(nameof(Name))
.Field(nameof(Age))
.Field(nameof(Address))
.Field(nameof(Information))
.Field(nameof(Email), validate: ValidateMailId)
.AddRemainingFields()
.OnCompletion(wrapUpRequest)
.Build();
}
Now, I want to pre-populate fields (Name, Age, Address) so that I can use it for editing as well.
回答1:
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.
回答2:
Sure you can pre-populate the formflow fields Firstly you will look for the fields that you want to populate and then add them to the entity list
I am using LUIS and if i find a suitable entity from my LUIS result i will add it to the form to be pre-populated.
var entities = new List<EntityRecommendation>(result.Entities);
if (entities.Any(e => e.Type == "IdNumber"))
{
entities.Add(new EntityRecommendation(type: "IdNumber") { Entity = entities.FirstOrDefault(e => e.Type == "IdNumber").Entity});
}
This will be done before you call your form to be built. Just make sure your "type" is the property name of your class. "Entity" will be the value
来源:https://stackoverflow.com/questions/40507449/can-form-flow-fields-in-bot-framework-be-pre-populated