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 30a6a11d39..4545024d6d 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 @@ -14,7 +14,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form public bool IsDisabled { get; set; } = false; [HtmlAttributeName("readonly")] - public bool IsReadonly { get; set; } = false; + public AbpReadonlyInputType IsReadonly { get; set; } = AbpReadonlyInputType.False; public bool AutoFocus { get; set; } 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 e31a2c8100..e38bd4e97a 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 @@ -121,14 +121,31 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form ConvertToTextAreaIfTextArea(inputTagHelperOutput); AddDisabledAttribute(inputTagHelperOutput); - AddReadOnlyAttribute(inputTagHelperOutput); AddAutoFocusAttribute(inputTagHelperOutput); isCheckbox = IsInputCheckbox(context, output, inputTagHelperOutput.Attributes); - inputTagHelperOutput.Attributes.AddClass(isCheckbox ? "form-check-input" : "form-control" + " " + GetSize(context,output)); + AddFormControlClass(context, output, isCheckbox, inputTagHelperOutput); + AddReadOnlyAttribute(inputTagHelperOutput); return inputTagHelperOutput; } + private void AddFormControlClass(TagHelperContext context, TagHelperOutput output, bool isCheckbox, TagHelperOutput inputTagHelperOutput) + { + var className = "form-control"; + var readonlyAttribute = GetAttribute(TagHelper.AspFor.ModelExplorer); + + if (isCheckbox) + { + className = "form-check-input"; + } + else if (TagHelper.IsReadonly == AbpReadonlyInputType.True_PlainText || (readonlyAttribute != null && readonlyAttribute.PlainText)) + { + className = "form-control-plaintext"; + } + + inputTagHelperOutput.Attributes.AddClass(className + " " + GetSize(context, output)); + } + protected virtual void AddAutoFocusAttribute(TagHelperOutput inputTagHelperOutput) { if (TagHelper.AutoFocus && !inputTagHelperOutput.Attributes.ContainsName("data-auto-focus")) @@ -139,11 +156,8 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form protected virtual void AddDisabledAttribute(TagHelperOutput inputTagHelperOutput) { - if (inputTagHelperOutput.Attributes.ContainsName("disabled")) - { - return; - } - else if (TagHelper.IsDisabled || GetAttribute(TagHelper.AspFor.ModelExplorer) != null) + if (inputTagHelperOutput.Attributes.ContainsName("disabled") == false && + (TagHelper.IsDisabled || GetAttribute(TagHelper.AspFor.ModelExplorer) != null)) { inputTagHelperOutput.Attributes.Add("disabled", ""); } @@ -151,11 +165,8 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form protected virtual void AddReadOnlyAttribute(TagHelperOutput inputTagHelperOutput) { - if (inputTagHelperOutput.Attributes.ContainsName("readonly")) - { - return; - } - else if (TagHelper.IsReadonly || GetAttribute(TagHelper.AspFor.ModelExplorer) != null) + if (inputTagHelperOutput.Attributes.ContainsName("readonly") == false && + (TagHelper.IsReadonly != AbpReadonlyInputType.False || GetAttribute(TagHelper.AspFor.ModelExplorer) != null)) { inputTagHelperOutput.Attributes.Add("readonly", ""); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpReadonlyInputType.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpReadonlyInputType.cs new file mode 100644 index 0000000000..415abf2ef7 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpReadonlyInputType.cs @@ -0,0 +1,9 @@ +namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form +{ + public enum AbpReadonlyInputType + { + False, + True, + True_PlainText + } +} diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/ReadOnlyInput.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/ReadOnlyInput.cs index 6cef8594b3..c63cd6d88c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/ReadOnlyInput.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/ReadOnlyInput.cs @@ -8,8 +8,15 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form [AttributeUsage(AttributeTargets.Property)] public class ReadOnlyInput : Attribute { + public bool PlainText { get; set; } + public ReadOnlyInput() { } + + public ReadOnlyInput(bool plainText) + { + PlainText = plainText; + } } }