1
votes

Let's say you're dynamically getting a list of passengers who can check in on a flight. The user needs to be able to select any number of passengers from the list to check in. I can make the dynamic list, but I can't figure out how to allow it to select multiple options. I've used the .SetAllowsMultiple(true) on the dynamic field but it doesn't work. I've looked at the formflow example in the documentation here but the example only allows for a single selection. How would you make it work with multiple selections?

Here's the property I placed in my CheckinDialog class:

public string Passenger { get; set; }

And here's my dynamic field:

.Field(new FieldReflector<CheckinDialog>(nameof(Passenger))
                                                        .SetAllowsMultiple(true)
                                                        .SetActive((state) =>
                                                        {
                                                            return CheckinDialog.Passengers != null && CheckinDialog.Passengers.Count > 0;
                                                        })
                                                        .SetPrompt(new PromptAttribute(Resources.Checkin.Passengers))
                                                        .SetType(null)
                                                        .SetDefine((state, field) =>
                                                        {
                                                            foreach (var pax in GetPassengers())
                                                                field
                                                                    .AddDescription(pax, pax)
                                                                    .AddTerms(pax, pax);
                                                            return TaskHelpers.FromResult(true);
                                                        }))
1
To get multiple values, you'll need a property that is capable of accepting multiple values. So you'll probably need a property of type List<Passenger>. You can take a look at the AnnotatedSandwich example. - Nick Trogh
Unfortunately, list properties don't appear to work with dynamic fields :( - Nate Graham
List properties are not indeed not supported (getting a NotImplementedException). You might revert to generating an Enum on the fly as a workaround, but not sure you want to get into that. - Nick Trogh

1 Answers

6
votes

One workaround for this will be launching the Form many times, meaning that once you complete the form for first time and select a passenger, in the callback of the form completion you can prompt the user if he wants to check another passenger. If the answer is yes, you can launch the form again.

This will mean that you will have to mantain the selection of the passengers and use that to filter the list of passengers to show in the form (to avoid check-in a passenger twice).

Here is some sample code that shows the approach (the PromptConfirm Dialog is missing)