FormFactory icon indicating copy to clipboard operation
FormFactory copied to clipboard

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

Open avani24897 opened this issue 5 years ago • 3 comments

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.

avani24897 avatar Mar 30 '20 04:03 avani24897

Could you post your code?

mcintyre321 avatar Mar 30 '20 08:03 mcintyre321

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?

avanisculptsoft avatar Mar 31 '20 11:03 avanisculptsoft

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, [email protected] 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 .

mcintyre321 avatar Apr 02 '20 18:04 mcintyre321