Support for collections
hashitha opened this issue · 3 comments
Are collections supported?
Something like this
[Title("Add new dynamic form")]
[Action("add", "Add")]
public class DynamicFormDialog
{
[Field(Name = "Sites")]
public List<string> SitesList { get; set; }
[Field(Name = "Form name")]
public string FormName { get; set; }
public DynamicFormDialog()
{
SitesList = new List<string>();
SitesList.Add("Site 1");
SitesList.Add("Site 2");
}
}
cc @redbaty
It turns out that implementing collections is much harder than it initially seems. Some problems that we needed to consider when allowing crud were:
- Tracking list count and item addition, removal, insertion - without ObservableCollection it's much harder.
- Transactional updates - you can "commit" an item once you hit the add/save button, but the fields update as you type, thus you need a transaction mechanism.
- Display style - how to display items? how to insert new items? This can depend on preference and data type.
There is a separate library for collections. I haven't touched anything there in a while so I'm not sure what state it's in.
I think for collections of primitives (string, int, date, etc) it would be easier to implement inline stacking of inputs, but for List<ComplexType>
it becomes a nightmare full of edge cases.
I will try if I can do something for List<Primitive>
from the main library, because it's super useful to have.
I am only looking for a very simple way to populate the combo box using a string like List<string>
. The items in this list won't be changed after constructing it. Basically, needs to load some values from a database for selection which is only done once at the object creation.
Would this help you?
[SelectFrom("{ContextBinding MySites}")] // get from viewmodel
public string SelectedSiteFromContext { get; set; }
[SelectFrom("{Binding MySites}")] // get from model
public string SelectedSiteFromModel { get; set; }
[FieldIgnore]
public List<string> MySites { get; set; } = new List<string> { "one", "two", "three" }