Aaltuj/VxFormGenerator

Nullable Types

Closed this issue · 4 comments

Hello thanks for the great work on this library
i just came across an issue, when one of my POCO fields is a nullable type (int?, bool? etc) i get this error:

blazor.server.js:15 [2020-10-06T21:54:43.076Z] Error: System.InvalidOperationException: Unable to set property 'ValueChanged' on object of type 'VxFormGenerator.Components.Bootstrap.BootstrapInputNumber`1[[System.Int32, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]'. The error was: Unable to cast object of type 'Microsoft.AspNetCore.Components.EventCallback`1[System.Nullable`1[System.Int32]]' to type 'Microsoft.AspNetCore.Components.EventCallback`1[System.Int32]'.
 ---> System.InvalidCastException: Unable to cast object of type 'Microsoft.AspNetCore.Components.EventCallback`1[System.Nullable`1[System.Int32]]' to type 'Microsoft.AspNetCore.Components.EventCallback`1[System.Int32]'.
   at Microsoft.AspNetCore.Components.Reflection.MemberAssignment.PropertySetter`2.SetValue(Object target, Object value)
   at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.<SetProperties>g__SetProperty|2_0(Object target, IPropertySetter writer, String parameterName, Object value)
   --- End of inner exception stack trace ---
   at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.<SetProperties>g__SetProperty|2_0(Object target, IPropertySetter writer, String parameterName, Object value)
   at Microsoft.AspNetCore.Components.Reflection.ComponentProperties.SetProperties(ParameterView& parameters, Object target)
   at Microsoft.AspNetCore.Components.ParameterView.SetParameterProperties(Object target)
   at Microsoft.AspNetCore.Components.Forms.InputBase`1.SetParametersAsync(ParameterView parameters)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.SetDirectParameters(ParameterView parameters)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
   at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()

by the way in my startup i am defining the initial setup as such:

        public FormGeneratorComponentsRepository BootstrapFormMapping = new FormGeneratorComponentsRepository(
            new Dictionary<string, Type>()
            {
                {typeof(string                                              ).ToString(), typeof(BootstrapInputText)                },
 
                {typeof(DateTime?                                           ).ToString(), typeof(InputDate<>)                       },
                {typeof(bool?                                               ).ToString(), typeof(BootstrapInputCheckbox)            },
                {typeof(decimal?                                            ).ToString(), typeof(BootstrapInputNumber<>)            },
                {typeof(Int32?                                              ).ToString(), typeof(BootstrapInputNumber<>)            },
                {typeof(Int64?                                              ).ToString(), typeof(BootstrapInputNumber<>)            },
                {typeof(float?                                              ).ToString(), typeof(BootstrapInputNumber<>)            },
                {typeof(double?                                             ).ToString(), typeof(BootstrapInputNumber<>)            },

                {typeof(Core.Entities.Project.Status 	                    ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },     
                {typeof(Core.Entities.Project.OrderType 	                ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.CustomerLayout 	            ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.CreditApprovalOptions         ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.FollowUpStatus 	            ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.FollowUpLossExplanation       ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.ShippingFOB 	                ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.ShippingVia 	                ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.ShippingMethod 	            ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.ShippingTruckSize 	        ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.Currency 	                    ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.TransportTruckType 	        ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.ProjectType 	                ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.ProductionType 	            ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.QCErrorZone 	                ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.QCErrorType 	                ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.BorderCrossing 	            ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.FollowUpStopExplanation       ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },
                {typeof(Core.Entities.Project.ProductionSource 	            ).ToString(), typeof(BootstrapInputSelectWithOptions<>) },

                //{typeof(ValueReferences<FoodKind>).ToString(), typeof(BootstrapInputCheckboxMultiple<>) },
                //{typeof(Color).ToString(), typeof(InputColor) }

            }, null, typeof(BootstrapFormElement<>));

thanks for any help or pointers on how to go around this issue.
cheers from Canada !!

hey @tkettani sorry didn't got a message about the issue. Yeah i haven't tried it with nullable types. Thanks for the pull request. I'll appreciate the input but I've added a new version that would split the component repos, so i close the pull request. . I'll take a look and incorporate your suggestion in the next version. I'm still in the progress of setting up the development pipeline and documentation. Take a look at the new master. That would render your ENUM (i assume) list redundant.

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Hi,
I have the same problem.
When this will be fixed?

this is already addressed in 0.4.0. So update to latest or if you have 0.4.0 you may have found a new bug: create an issue with the reproduction steps.