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

Programmatically Created Form - Nested Forms Example #50

Closed janamargaret closed 6 years ago

janamargaret commented 7 years ago

Hello! Do you have any code examples of how to get either of the Nested Forms examples on http://formfactoryaspmvc.azurewebsites.net/) working for a Programmatically Created Form?

mcintyre321 commented 7 years ago

No... I think you can maybe use an object as the outer item:



    new PropertyVm(typeof(object), "outer") //<!- 
     {
         DisplayName = ...,
         Value = ... inner PropertyVm[] ,
         ...
    {
}
stumpk commented 7 years ago

Thanks for the great work. Sorry if I am doing something obviously wrong, I've just started playing with FromFactory. I am trying to do this as well, but when I put a PropertyVm array in for the Value of the object, I am System.StackOverflowException. Any ideas what I am missing?

Thanks

mcintyre321 commented 7 years ago

Can you send me a code snippet please?

On 17 Aug 2017 00:39, "stumpk" notifications@github.com wrote:

Thanks for the great work. Sorry if I am doing something obviously wrong, I've just started playing with FromFactory. I am trying to do this as well, but when I put a PropertyVm array in for the Value of the object, I am System.StackOverflowException. Any ideas what I am missing?

Thanks

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mcintyre321/FormFactory/issues/50#issuecomment-322928831, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQ0-pDP_xNut_a1vCL3JlVviBVjI4qBks5sY33BgaJpZM4Op3kB .

stumpk commented 7 years ago

Of course. Right now I am just playing around with the example code. Please see below:

       var lasers = new[] {
             new PropertyVm(typeof(string) , "Left")
                {
                    DisplayName = "Left",
                    NotOptional =true,
                    GetCustomAttributes = () => new object[] { new DataTypeAttribute("TitleTol") }
                },
              new PropertyVm(typeof(string) , "Right")
                {
                    DisplayName = "Right",
                    NotOptional =true,
                    GetCustomAttributes = () => new object[] { new DataTypeAttribute("TitleTol") }
                },
               new PropertyVm(typeof(string) , "Ceiling")
                {
                    DisplayName = "Ceiling",
                    NotOptional =true,
                    GetCustomAttributes = () => new object[] { new DataTypeAttribute("TitleTol") }
                },
                new PropertyVm(typeof(string) , "Sagital")
                {
                    DisplayName = "Sagital",
                    NotOptional =true,
                    GetCustomAttributes = () => new object[] { new DataTypeAttribute("TitleTol") }
                },
        };

        var formModel = new[]
       {
                new PropertyVm(typeof(object) , "outer")
                {
                    DisplayName = "Laser Alignment",
                    NotOptional =true,
                    Value=lasers
                },

          };
mcintyre321 commented 6 years ago

Ah I can see the problem. PropertyVms aren't designed to be nested, instead they should be rendered as a flat list.

If you want to do what you are after, try putting the parent item name into each PropertyVms name e.g. for Left, use outer.Left :

var lasers = new[] {
             new PropertyVm(typeof(string) , "outer.Left")
                {
                    DisplayName = "Left",
                    NotOptional =true,
                    GetCustomAttributes = () => new object[] { new DataTypeAttribute("TitleTol") }
                },
              new PropertyVm(typeof(string) , "outer.Right")
                {
                    DisplayName = "Right",
                    NotOptional =true,
                    GetCustomAttributes = () => new object[] { new DataTypeAttribute("TitleTol") }
                },
               new PropertyVm(typeof(string) , "outer.Ceiling")
                {
                    DisplayName = "Ceiling",
                    NotOptional =true,
                    GetCustomAttributes = () => new object[] { new DataTypeAttribute("TitleTol") }
                },
                new PropertyVm(typeof(string) , "outer.Sagital")
                {
                    DisplayName = "Sagital",
                    NotOptional =true,
                    GetCustomAttributes = () => new object[] { new DataTypeAttribute("TitleTol") }
                },
        };