Beispiel #1
0
        public void BuildRendererTree(
            IFormLayout <TModel> createFormLayout,
            CreateItemRendererContext <TModel> createItemRendererContext,
            IRendererTreeBuilder rendererTreeBuilder)
        {
            var bodyAction   = createFormLayout.BuildBodyRendererTree(createItemRendererContext, formInputRendererTreeProvider);
            var footerAction = createFormLayout.BuildFooterRendererTree(createItemRendererContext);

            RenderFragment <EditContext> formBody = (EditContext context) => delegate(RenderTreeBuilder builder)
            {
                var internalBuilder = new BlazorRendererTreeBuilder(builder);
                bodyAction?.Invoke(internalBuilder);
                footerAction?.Invoke(internalBuilder);

                internalBuilder
                .OpenComponent(typeof(DataAnnotationsValidator))
                .CloseComponent();
            };

            rendererTreeBuilder
            .OpenComponent(typeof(EditForm))
            .AddAttribute(nameof(EditContext), createItemRendererContext.ViewModel.EditContext)
            .AddAttribute("OnValidSubmit", eventCallbackFactory.Create <EditContext>(this,
                                                                                     context => createItemRendererContext.ViewModel.SaveAction.Invoke(createItemRendererContext.ViewModel.Model)))
            .AddAttribute(RenderTreeBuilder.ChildContent, formBody)
            .CloseComponent();

            createItemRendererContext.ViewModel.ValidateModel();
        }
Beispiel #2
0
        public static IRendererTreeBuilder AddValidationMessage <T>(this IRendererTreeBuilder rendererTreeBuilder, LambdaExpression lambdaExpression)
        {
            rendererTreeBuilder
            .OpenComponent(typeof(ValidationMessage <>).MakeGenericType(typeof(T)))
            .AddAttribute("For", lambdaExpression)
            .CloseComponent();

            return(rendererTreeBuilder);
        }