I'm having trouble correctly setting up a multiselect so that I can edit the data in my app. More specifically, I'm creating a form so that you can edit the details of a Client, including their favorite foods. I want to have a multiselect in that form where you can see the list of checked favorite foods across a list of allowable foods (as determined by one of the fields in the Food model).
For my data model, I have a one-to-many relation between "Clients" (one, from the Client model) and "Favorite Foods" (many, from the Food model).
The problem I'm having is that the options
field for a multiselect ends up being a List<String>
(@model.Food.fields.Name.possibleValues
). However, I can't figure out what I need to put in the values
field. My inclination is to want to be able to put @datasource.item.FavoriteFoods
but I can't end up choosing that, presumably because it's List<Food record>
and not a List<String>
result. (That assumption could be wrong, I don't know why I can't select that.)
Anyone know how you're supposed to actually do this? I'm more sure my options
selection is the right way to put the list of options, so I think I just don't know what's normal to put in the values
section.
Based on your problem description, this is what I've done...
I created a model named clients and a model named favoriteFoods.
Then I set up the relation clients(ONE) - (MANY) favoriteFoods.
Next. I created some test favoriteFoods records and some test clients records.
Then in a test page I inserted an edit form with the datasource being clients.
This is how it looks:
I had to manually insert the multiselect widget because it was not available by default. Then I set up the multiselect bindings as follows:
options: @datasources.favoriteFoods.items
values: @datasource.item.favoriteFoods
Finally, preview the app and you should be able to see the following behavior:
P.S. If the widget was already inserted before you created the relations or models, chances are that you need to delete the widget and insert it again. I hope this helps!