From 8b6a3757e9dd5c58b2ba0d16feb1b7a3a4be3ff5 Mon Sep 17 00:00:00 2001 From: masoodkhoshgard Date: Thu, 20 Jul 2023 13:26:12 +0330 Subject: [PATCH] revert Improved display for Floating Labels --- .../Form/AbpInputTagHelperService.cs | 7 +-- .../Form/AbpSelectTagHelperService.cs | 59 ++++++++++++------- 2 files changed, 41 insertions(+), 25 deletions(-) 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 9923e57de0..981116aa9f 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 @@ -227,11 +227,10 @@ protected virtual void AddPlaceholderAttribute(TagHelperOutput inputTagHelperOut var attribute = TagHelper.AspFor.ModelExplorer.GetAttribute(); - if (attribute != null || TagHelper.FloatingLabel) + if (attribute != null) { - var placeholderLocalized = _tagHelperLocalizer.GetLocalizedText(attribute?.Value ?? string.Empty, TagHelper.AspFor.ModelExplorer); - if (string.IsNullOrWhiteSpace(placeholderLocalized)) - placeholderLocalized = TagHelper.AspFor.Name; + var placeholderLocalized = _tagHelperLocalizer.GetLocalizedText(attribute.Value, TagHelper.AspFor.ModelExplorer); + inputTagHelperOutput.Attributes.Add("placeholder", placeholderLocalized); } } 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 82f4393c3b..0edc8f1008 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 @@ -1,14 +1,15 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text.Encodings.Web; -using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc.Diagnostics; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.TagHelpers; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.Extensions.Localization; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text.Encodings.Web; +using System.Threading.Tasks; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.Microsoft.AspNetCore.Razor.TagHelpers; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Extensions; using Volo.Abp.Localization; @@ -37,7 +38,7 @@ public AbpSelectTagHelperService( _abpEnumLocalizer = abpEnumLocalizer; } - public async override Task ProcessAsync(TagHelperContext context, TagHelperOutput output) + public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { var childContent = await output.GetChildContentAsync(); @@ -73,8 +74,7 @@ protected virtual async Task GetFormInputGroupAsHtmlAsync(TagHelperConte var validation = await GetValidationAsHtmlAsync(context, output, selectTag); var infoText = GetInfoAsHtml(context, output, selectTag); - return TagHelper.FloatingLabel ? selectAsHtml + Environment.NewLine + label + Environment.NewLine + infoText + Environment.NewLine + validation : - label + Environment.NewLine + selectAsHtml + Environment.NewLine + infoText + Environment.NewLine + validation; + return label + Environment.NewLine + selectAsHtml + Environment.NewLine + infoText + Environment.NewLine + validation; } protected virtual string SurroundInnerHtmlAndGet(TagHelperContext context, TagHelperOutput output, string innerHtml) @@ -156,15 +156,23 @@ protected virtual List GetSelectItems(TagHelperContext context, } var selectItemsAttribute = TagHelper.AspFor.ModelExplorer.GetAttribute(); - return selectItemsAttribute != null - ? GetSelectItemsFromAttribute(selectItemsAttribute, TagHelper.AspFor.ModelExplorer) - : throw new Exception("No items provided for select attribute."); + if (selectItemsAttribute != null) + { + return GetSelectItemsFromAttribute(selectItemsAttribute, TagHelper.AspFor.ModelExplorer); + } + + throw new Exception("No items provided for select attribute."); } private bool IsEnum() { var value = TagHelper.AspFor.Model; - return (value != null && value.GetType().IsEnum) || TagHelper.AspFor.ModelExplorer.Metadata.IsEnum; + if (value != null && value.GetType().IsEnum) + { + return true; + } + + return TagHelper.AspFor.ModelExplorer.Metadata.IsEnum; } protected virtual async Task GetLabelAsHtmlAsync(TagHelperContext context, TagHelperOutput output, TagHelperOutput selectTag) @@ -288,7 +296,12 @@ protected virtual List GetSelectItemsFromAttribute( { var selectItems = selectItemsAttribute.GetItems(explorer)?.ToList(); - return selectItems ?? new List(); + if (selectItems == null) + { + return new List(); + } + + return selectItems; } protected virtual async Task GetLabelAsHtmlUsingTagHelperAsync(TagHelperContext context, TagHelperOutput output) @@ -324,13 +337,17 @@ protected virtual string GetSize(TagHelperContext context, TagHelperOutput outpu TagHelper.Size = attribute.Size; } - return TagHelper.Size switch + switch (TagHelper.Size) { - AbpFormControlSize.Small => "form-select-sm", - AbpFormControlSize.Medium => "form-select-md", - AbpFormControlSize.Large => "form-select-lg", - _ => "", - }; + case AbpFormControlSize.Small: + return "form-select-sm"; + case AbpFormControlSize.Medium: + return "form-select-md"; + case AbpFormControlSize.Large: + return "form-select-lg"; + } + + return ""; } protected virtual TagHelperAttributeList GetInputAttributes(TagHelperContext context, TagHelperOutput output) @@ -359,7 +376,7 @@ protected virtual void LeaveOnlyGroupAttributes(TagHelperContext context, TagHel foreach (var tagHelperAttribute in tagHelperAttributes) { - var nameWithoutPrefix = tagHelperAttribute.Name[groupPrefix.Length..]; + var nameWithoutPrefix = tagHelperAttribute.Name.Substring(groupPrefix.Length); var newAttritube = new TagHelperAttribute(nameWithoutPrefix, tagHelperAttribute.Value); output.Attributes.Add(newAttritube); }