FormFactory icon indicating copy to clipboard operation
FormFactory copied to clipboard

How to add editable collection in Programatically created form?

Open TonyWoo opened this issue 5 years ago • 4 comments

Thanks for provided so great library, just has a question, how to add editable collection in Programatically created form?

TonyWoo avatar May 29 '19 06:05 TonyWoo

Something like:

var formModel = new[]
            {
                    new PropertyVm(typeof(List<Movie>) , "movies")
                    {
                        DisplayName = "Movies",
                        NotOptional =true,
                        Value = new List<Movie>()
                        {
                             new Movie() {Title = "Fight Club"},
                             new Movie() {Title = "The Silent Partner" },
                             new Movie() {Title = "Bambi"},
                        }                        
                    },
};

...
 
    public class Movie
    {
        [Required]
        [StringLength(64, MinimumLength = 2)]
        public string Title { get; set; }
    }

mcintyre321 avatar May 29 '19 08:05 mcintyre321

It's a bit more complex if you want to have a list of programatically created types, rather than a static type (like Movie).

mcintyre321 avatar May 29 '19 08:05 mcintyre321

Thanks for you quick reply @mcintyre321. I'd like build a form builder and user want to add some collection data. It seems the item type like Movie should be static type, not sure how to do it dynamically. thanks.

TonyWoo avatar May 29 '19 08:05 TonyWoo

Did the above work for you?

mcintyre321 avatar Nov 06 '19 09:11 mcintyre321