From b95ddd50c69200e4b6486b0efa500b8db4500d83 Mon Sep 17 00:00:00 2001 From: yekalkan Date: Tue, 1 May 2018 15:13:16 +0300 Subject: [PATCH] Added validation to input group --- .../Form/AbpInputTagHelperService.cs | 27 +++++++++++++++---- .../Form/AbpSelectTagHelperService.cs | 3 +-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs index 9259b7aaf6..7084b81877 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs @@ -31,7 +31,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form var order = GetInputOrder(TagHelper.AspFor.ModelExplorer); - AddGroupToFormGroupContents(context,TagHelper.AspFor.Name, html, order); + AddGroupToFormGroupContents(context, TagHelper.AspFor.Name, html, order); output.SuppressOutput(); } @@ -42,16 +42,33 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form var inputHtml = RenderTagHelperOutput(inputTag, _encoder); var label = GetLabelAsHtml(inputTag, isCheckbox); - return GetContent(label, inputHtml, isCheckbox); + var validation = isCheckbox ? "" : GetValidationAsHtml(context); + + return GetContent(label, inputHtml, validation, isCheckbox); + } + protected virtual string GetValidationAsHtml(TagHelperContext context) + { + var validationMessageTagHelper = new ValidationMessageTagHelper(_generator) + { + For = TagHelper.AspFor, + ViewContext = TagHelper.ViewContext + }; + + var attributeList = new TagHelperAttributeList { { "class", "form-control" } }; + + return RenderTagHelper(attributeList, context, validationMessageTagHelper, _encoder, "span", TagMode.StartTagAndEndTag); } - protected virtual string GetContent(string label, string inputHtml, bool isCheckbox) + protected virtual string GetContent(string label, string inputHtml, string validation, bool isCheckbox) { var innerContent = isCheckbox ? inputHtml + Environment.NewLine + label : label + Environment.NewLine + inputHtml; - return "
" + Environment.NewLine + innerContent + Environment.NewLine + "
"; + return "
" + + Environment.NewLine + innerContent + Environment.NewLine + + Environment.NewLine + validation + Environment.NewLine + + "
"; } protected virtual TagHelperOutput GetInputTag(TagHelperContext context, out bool isCheckbox) @@ -81,7 +98,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form { return ""; } - + var checkboxClass = isCheckbox ? "class=\"form-check-label\" " : ""; return "