From 23a57fa89721f42939705751b656426a13eb287f Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Thu, 20 Dec 2018 09:13:33 +0300 Subject: [PATCH] added placeholder attribute to input tag helper --- .../Form/AbpInputTagHelperService.cs | 16 ++++++++++++++++ .../TagHelpers/Form/Placeholder.cs | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/Placeholder.cs 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 e38bd4e97a..7077dfef8d 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 @@ -125,6 +125,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form isCheckbox = IsInputCheckbox(context, output, inputTagHelperOutput.Attributes); AddFormControlClass(context, output, isCheckbox, inputTagHelperOutput); AddReadOnlyAttribute(inputTagHelperOutput); + AddPlaceholderAttribute(inputTagHelperOutput); return inputTagHelperOutput; } @@ -172,6 +173,21 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form } } + protected virtual void AddPlaceholderAttribute(TagHelperOutput inputTagHelperOutput) + { + if (inputTagHelperOutput.Attributes.ContainsName("placeholder")) + { + return; + } + + var attribute = GetAttribute(TagHelper.AspFor.ModelExplorer); + + if (attribute != null) + { + inputTagHelperOutput.Attributes.Add("placeholder", attribute.Value); + } + } + protected virtual bool IsInputCheckbox(TagHelperContext context, TagHelperOutput output, TagHelperAttributeList attributes) { return attributes.Any(a => a.Value != null && a.Name == "type" && a.Value.ToString() == "checkbox"); diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/Placeholder.cs b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/Placeholder.cs new file mode 100644 index 0000000000..042efb67c2 --- /dev/null +++ b/framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/Placeholder.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form +{ + [AttributeUsage(AttributeTargets.Property)] + public class Placeholder : Attribute + { + public string Value { get; set; } + + public Placeholder(string value) + { + Value = value; + } + } +}