mcintyre321 / FormFactory

MVC5, Core or standalone - Generate rich HTML5 forms from your ViewModels, or build them programatically
http://formfactoryaspmvc.azurewebsites.net/
MIT License
303 stars 103 forks source link

How to render Nested ViewModels, collections #44

Closed weedkiller closed 6 years ago

weedkiller commented 7 years ago

hi I saw the one sample on collections, fro ASP MVC 5

walking down the collection StudentWeekVM but I was not able to get it to work with 2 nesting levels - can you please show me how I would wire this up? and on submit does it submit the entire StudentWeekVM collection it contains

For ex. show the Student Week Schedule with student Hours,

mcintyre321 commented 7 years ago

There's a pull request open with some code to fix that, but it needs work before I accept it: https://github.com/mcintyre321/FormFactory/pull/34

You can maybe use the changed FormFactory.js from that? On Wed, 22 Feb 2017 at 18:56, weedkiller notifications@github.com wrote:

hi I saw the one sample on collections,

but I was not able to get it to work with 2 nesting levels

For ex. show the Student Week Schedule with student Hours,

-

showing days on top <monday, tuesday, >

and classes on the side like this image http://bit.ly/2lGumKB

 public class StudentWeekVM
 {
     public StudentWeekVM()
     {
         Records = new List<ClassTimeGroupVM>();
         Totals = new List<LabHoursEnteryVM>();
         for (int i = 0; i < 7; i++)
         {
             Totals.Add(new LabHoursEnteryVM());
         }
     }
     [DisplayFormat(DataFormatString = "{0:dddd d MMMM yyyy}")]
     public DateTime WeekEnding { get; set; }
     public StudentVM Student { get; set; }
     public List<ClassTimeGroupVM> Records { get; set; }
     public List<LabHoursEnteryVM> Totals { get; set; }
     public decimal GrandTotal { get; set; }
     public int SelectedProject { get; set; }
     public int SelectedClassDayOrNight { get; set; }
     public IEnumerable<SelectListItem> Projects { get; set; }
     public IEnumerable<SelectListItem> ClassDayOrNights { get; set; }
 }

 public class ClassTimeGroupVM
 {
     public ClassTimeGroupVM()
     {
         TimeRecords = new List<LabHoursEnteryVM>();
         Total = new LabHoursEnteryVM();
         for (int i = 0; i < 7; i++)
         {
             TimeRecords.Add(new LabHoursEnteryVM());
         }
     }
     public ClassDayOrNightVM ClassDayOrNight { get; set; }
     public List<LabHoursEnteryVM> TimeRecords { get; set; }
     public LabHoursEnteryVM Total { get; set; }
 }
 public class ClassDayOrNightVM
 {
     public int ID { get; set; }
     public string Name { get; set; }
     public ClassesVM Project { get; set; }
 }
 public class LabHoursEnteryVM
 {
     public int? ID { get; set; }
     public decimal Hours { get; set; }
 }

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mcintyre321/FormFactory/issues/44, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQ0-gzCYGbFtyxRoc-RDrOBYnmJNICyks5rfITMgaJpZM4MJC6v .

reiphil commented 6 years ago

@mcintyre321 - hey, just wondering if there has been any movement on nested collections or how we should interact/use them.

mcintyre321 commented 6 years ago

The PR with nested collections can't be accepted in it's current state. If someone is able to extract the code from that PR for making the nested collections work and send a PR I will happily accept.