diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs index b22d33cc64..6b7c32d05f 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs @@ -8,6 +8,8 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form { public ModelExpression AspFor { get; set; } + public string Label { get; set; } + [HtmlAttributeName("disabled")] public bool IsDisabled { get; set; } 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 fd52ab668c..cc7a5a0372 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 @@ -50,7 +50,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form { var inputTag = GetInputTag(context, output, out isCheckbox); var inputHtml = RenderTagHelperOutput(inputTag, _encoder); - var label = GetLabelAsHtml(context, output, isCheckbox); + var label = GetLabelAsHtml(context, output, inputTag, isCheckbox); var validation = isCheckbox ? "" : GetValidationAsHtml(context, output); @@ -112,7 +112,21 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form return attributes.Any(a => a.Value != null && a.Name == "type" && a.Value.ToString() == "checkbox"); } - protected virtual string GetLabelAsHtml(TagHelperContext context, TagHelperOutput output, bool isCheckbox) + protected virtual string GetLabelAsHtml(TagHelperContext context, TagHelperOutput output, TagHelperOutput inputTag, bool isCheckbox) + { + if (string.IsNullOrEmpty(TagHelper.Label)) + { + return GetLabelAsHtmlUsingTagHelper(context,output,isCheckbox); + } + + var checkboxClass = isCheckbox ? "class=\"form-check-label\" " : ""; + + return ""; + } + + protected virtual string GetLabelAsHtmlUsingTagHelper(TagHelperContext context, TagHelperOutput output, bool isCheckbox) { var labelTagHelper = new LabelTagHelper(_generator) { diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs index dfe8579119..889fe4208d 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs @@ -9,6 +9,8 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form { public ModelExpression AspFor { get; set; } + public string Label { get; set; } + public IEnumerable AspItems { get; set; } [HtmlAttributeNotBound] diff --git a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs index dd2dbe1b9a..25b8622ac1 100644 --- a/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs +++ b/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs @@ -17,13 +17,11 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form { private readonly IHtmlGenerator _generator; private readonly HtmlEncoder _encoder; - private readonly IStringLocalizer _localizer; - public AbpSelectTagHelperService(IHtmlGenerator generator, HtmlEncoder encoder, IStringLocalizer localizer) + public AbpSelectTagHelperService(IHtmlGenerator generator, HtmlEncoder encoder) { _generator = generator; _encoder = encoder; - _localizer = localizer; } public override void Process(TagHelperContext context, TagHelperOutput output) @@ -51,7 +49,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form { var selectTag = GetSelectTag(context, output); var selectAsHtml = RenderTagHelperOutput(selectTag, _encoder); - var label = GetLabelAsHtml(context, output); + var label = GetLabelAsHtml(context, output, selectTag); return label + Environment.NewLine + selectAsHtml; } @@ -95,6 +93,16 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form return selectItems; } + protected virtual string GetLabelAsHtml(TagHelperContext context, TagHelperOutput output, TagHelperOutput selectTag) + { + if (string.IsNullOrEmpty(TagHelper.Label)) + { + return GetLabelAsHtmlUsingTagHelper(context, output); + } + + return ""; + } + protected virtual bool GetSelectItemsIfProvidedByEnum(TagHelperContext context, TagHelperOutput output, ModelExplorer explorer, out List selectItems) { selectItems = explorer.Metadata.IsEnum ? explorer.ModelType.GetTypeInfo().GetMembers(BindingFlags.Public | BindingFlags.Static) @@ -143,17 +151,15 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form return TagHelper.AspFor.ModelExplorer.Model?.ToString(); } - protected virtual string GetLabelAsHtml(TagHelperContext context, TagHelperOutput output) + protected virtual string GetLabelAsHtmlUsingTagHelper(TagHelperContext context, TagHelperOutput output) { var labelTagHelper = new LabelTagHelper(_generator) { For = TagHelper.AspFor, ViewContext = TagHelper.ViewContext }; - - var attributeList = new TagHelperAttributeList(); - - return RenderTagHelper(attributeList, context, labelTagHelper, _encoder, "span", TagMode.StartTagAndEndTag, true); + + return RenderTagHelper(new TagHelperAttributeList(), context, labelTagHelper, _encoder, "span", TagMode.StartTagAndEndTag, true); } } } \ No newline at end of file