diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs index 4545024d6d..8bd4021458 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs @@ -10,6 +10,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form public string Label { get; set; } + [HtmlAttributeName("info")] + public string InfoText { get; set; } + [HtmlAttributeName("disabled")] public bool IsDisabled { get; set; } = false; diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs index 13ab0f9159..a4a0193e97 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs @@ -58,10 +58,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form protected virtual string GetFormInputGroupAsHtml(TagHelperContext context, TagHelperOutput output, out bool isCheckbox) { var inputTag = GetInputTagHelperOutput(context, output, out isCheckbox); + var inputHtml = RenderTagHelperOutput(inputTag, _encoder); var label = GetLabelAsHtml(context, output, inputTag, isCheckbox); var info = GetInfoAsHtml(context, output, inputTag, isCheckbox); - var validation = isCheckbox ? "" : GetValidationAsHtml(context, output, inputTag); return GetContent(context, output, label, inputHtml, validation, info, isCheckbox); @@ -88,11 +88,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form protected virtual string GetContent(TagHelperContext context, TagHelperOutput output, string label, string inputHtml, string validation, string infoHtml, bool isCheckbox) { var innerContent = isCheckbox ? - inputHtml + Environment.NewLine + label : - label + Environment.NewLine + inputHtml; + inputHtml + label : + label + inputHtml; - return Environment.NewLine + innerContent + Environment.NewLine + - Environment.NewLine + validation + Environment.NewLine + infoHtml; + return innerContent + infoHtml + validation; } protected virtual string SurroundInnerHtmlAndGet(TagHelperContext context, TagHelperOutput output, string innerHtml, bool isCheckbox) @@ -259,23 +258,29 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form return ""; } - var infoAttribute = GetAttribute(TagHelper.AspFor.ModelExplorer); - if (infoAttribute == null) + string text = ""; + + if (!string.IsNullOrEmpty(TagHelper.InfoText)) { - return ""; + text = TagHelper.InfoText; } - - var idAttr = inputTag.Attributes.FirstOrDefault(a => a.Name == "id"); - - if (idAttr == null) + else { - return ""; + var infoAttribute = GetAttribute(TagHelper.AspFor.ModelExplorer); + if (infoAttribute != null) + { + text = infoAttribute.Text; + } + else + { + return ""; + } } - var id = idAttr.Value + "InfoText"; + var idAttr = inputTag.Attributes.FirstOrDefault(a => a.Name == "id"); - return "" + - LocalizeText(infoAttribute.Text) + + return "" + + LocalizeText(text) + ""; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpRadioInputTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpRadioInputTagHelperService.cs index 6dee6c1371..13585eeaf2 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpRadioInputTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpRadioInputTagHelperService.cs @@ -31,7 +31,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form var html = GetHtml(context, output, selectItems); - AddGroupToFormGroupContents(context, TagHelper.AspFor.Name, html, order, out var surpress); if (surpress) diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs index 3cb2fd4667..8a1890f4dc 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs @@ -15,6 +15,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form public AbpFormControlSize Size { get; set; } = AbpFormControlSize.Default; + [HtmlAttributeName("info")] + public string InfoText { get; set; } + [HtmlAttributeNotBound] [ViewContext] public ViewContext ViewContext { get; set; } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs index ca1c2e51ff..fa3d987135 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs @@ -58,8 +58,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form var selectAsHtml = RenderTagHelperOutput(selectTag, _encoder); var label = GetLabelAsHtml(context, output, selectTag); var validation = GetValidationAsHtml(context, output, selectTag); + var infoText = GetInfoAsHtml(context, output, selectTag); - return label + Environment.NewLine + selectAsHtml + Environment.NewLine + validation; + return label + Environment.NewLine + selectAsHtml + Environment.NewLine + infoText+ Environment.NewLine + validation; } protected virtual string SurroundInnerHtmlAndGet(TagHelperContext context, TagHelperOutput output, string innerHtml) @@ -76,13 +77,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form ViewContext = TagHelper.ViewContext }; - var inputTagHelperOutput = GetInnerTagHelper(GetInputAttributes(context, output), context, selectTagHelper, "select", TagMode.StartTagAndEndTag); + var selectTagHelperOutput = GetInnerTagHelper(GetInputAttributes(context, output), context, selectTagHelper, "select", TagMode.StartTagAndEndTag); - inputTagHelperOutput.Attributes.AddClass("form-control"); - inputTagHelperOutput.Attributes.AddClass(GetSize(context,output)); - AddDisabledAttribute(inputTagHelperOutput); + selectTagHelperOutput.Attributes.AddClass("form-control"); + selectTagHelperOutput.Attributes.AddClass(GetSize(context,output)); + AddDisabledAttribute(selectTagHelperOutput); + AddInfoTextId(selectTagHelperOutput); - return inputTagHelperOutput; + return selectTagHelperOutput; } protected virtual void AddDisabledAttribute(TagHelperOutput inputTagHelperOutput) @@ -119,6 +121,64 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form return GetLabelAsHtmlUsingTagHelper(context, output); } + protected virtual void AddInfoTextId(TagHelperOutput inputTagHelperOutput) + { + if (GetAttribute(TagHelper.AspFor.ModelExplorer) == null) + { + return; + } + + var idAttr = inputTagHelperOutput.Attributes.FirstOrDefault(a => a.Name == "id"); + + if (idAttr == null) + { + return; + } + + inputTagHelperOutput.Attributes.Add("aria-describedby", LocalizeText(idAttr.Value + "InfoText")); + } + + protected virtual string GetInfoAsHtml(TagHelperContext context, TagHelperOutput output, TagHelperOutput inputTag) + { + string text = ""; + + if (!string.IsNullOrEmpty(TagHelper.InfoText)) + { + text = TagHelper.InfoText; + } + else + { + var infoAttribute = GetAttribute(TagHelper.AspFor.ModelExplorer); + if (infoAttribute != null) + { + text = infoAttribute.Text; + } + else + { + return ""; + } + } + + var idAttr = inputTag.Attributes.FirstOrDefault(a => a.Name == "id"); + + return "" + + LocalizeText(text) + + ""; + } + + protected virtual string LocalizeText(string text) + { + IStringLocalizer localizer = null; + var resourceType = _options.AssemblyResources.GetOrDefault(TagHelper.AspFor.ModelExplorer.ModelType.Assembly); + + if (resourceType != null) + { + localizer = _stringLocalizerFactory.Create(resourceType); + } + + return localizer == null ? text : localizer[text].Value; + } + protected virtual bool GetSelectItemsIfProvidedByEnum(TagHelperContext context, TagHelperOutput output, ModelExplorer explorer, out List selectItems) { IStringLocalizer localizer = null;