mcintyre321 / FormFactory

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

Client validations not working when using PropertyVms to create Dynamic Forms. #95

Open avani24897 opened 4 years ago

avani24897 commented 4 years ago

https://github.com/mcintyre321/FormFactory/issues/73#issuecomment-419052881

I've tried to add a RequiredAttribute into the GetCustomAttributes Func as you mentioned in the above issue. But somehow client validations not working in my case. If possible then give some suggestions on how to use RequiredAttribute into the GetCustomAttributes Func.

I'm using PropertyVms to create Dynamic Forms where my model is also dynamic to create PropertyVms. So I'm unable to use FormFactory.Attributes.

Thanks in advance.

mcintyre321 commented 4 years ago

Could you post your code?

avanisculptsoft commented 4 years ago

Sorry for the delay and thanks for your quick response. Somehow I was misplaced my code for the required validation attribute. Now it's working properly for validations.

But I faced one more problem with nested forms creation in dynamic PropertyVms. It always gives exception the same as https://github.com/mcintyre321/FormFactory/issues/50#issuecomment-322928831.

My code is as below,

    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") }
            },
        }

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

I also tried it with choices such as https://github.com/mcintyre321/FormFactory/issues/81#issuecomment-490255091 but unfortunately, it doesn't fulfill my requirements with TextBox control. Is there any other way to do the same?

mcintyre321 commented 4 years ago

One thing you can do is create a static model that does what you want (like in the examples), then call ToPropertyVms() on it, then examine it in the debugger, that shows you what objects you need

On Tue, 31 Mar 2020, 12:41 avanisculptsoft, notifications@github.com wrote:

Sorry for the delay and thanks for your quick response. Somehow I was misplaced my code for the required validation attribute. Now it's working properly for validations.

But I faced one more problem with nested forms creation in dynamic PropertyVms. It always gives exception the same as #50 (comment) https://github.com/mcintyre321/FormFactory/issues/50#issuecomment-322928831 .

My code is as below, `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") } }, };

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

I also tried it with choices such as #81 (comment) https://github.com/mcintyre321/FormFactory/issues/81#issuecomment-490255091 but unfortunately, it doesn't fulfill my requirements with TextBox control. Is there any other way to do the same?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/mcintyre321/FormFactory/issues/95#issuecomment-606575341, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACDJ6U3RRUPDL5OHYBPLHTRKHJH5ANCNFSM4LWIVYMQ .