Added ReadOnlyInput and DisabledInput attributes to tag helpers

pull/598/head
Yunus Emre Kalkan 6 years ago
parent 7de9e80332
commit a4bbf9e480

@ -120,21 +120,41 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
var inputTagHelperOutput = GetInnerTagHelper(GetInputAttributes(context, output), context, tagHelper, "input");
ConvertToTextAreaIfTextArea(inputTagHelperOutput);
AddDisabledAttribute(inputTagHelperOutput);
AddReadOnlyAttribute(inputTagHelperOutput);
AddAutoFocusAttribute(inputTagHelperOutput);
isCheckbox = IsInputCheckbox(context, output, inputTagHelperOutput.Attributes);
inputTagHelperOutput.Attributes.AddClass(isCheckbox ? "form-check-input" : "form-control");
if (TagHelper.IsDisabled && !inputTagHelperOutput.Attributes.ContainsName("disabled"))
{
inputTagHelperOutput.Attributes.Add("disabled", "true");
}
return inputTagHelperOutput;
}
protected virtual void AddAutoFocusAttribute(TagHelperOutput inputTagHelperOutput)
{
if (TagHelper.AutoFocus && !inputTagHelperOutput.Attributes.ContainsName("data-auto-focus"))
{
inputTagHelperOutput.Attributes.Add("data-auto-focus", "true");
}
}
isCheckbox = IsInputCheckbox(context, output, inputTagHelperOutput.Attributes);
inputTagHelperOutput.Attributes.AddClass(isCheckbox ? "form-check-input" : "form-control");
protected virtual void AddDisabledAttribute(TagHelperOutput inputTagHelperOutput)
{
var disabledAttribute = GetAttribute<DisabledInput>(TagHelper.AspFor.ModelExplorer);
return inputTagHelperOutput;
if (disabledAttribute != null && !inputTagHelperOutput.Attributes.ContainsName("disabled"))
{
inputTagHelperOutput.Attributes.Add("disabled", "");
}
}
protected virtual void AddReadOnlyAttribute(TagHelperOutput inputTagHelperOutput)
{
var readOnlyAttribute = GetAttribute<ReadOnlyInput>(TagHelper.AspFor.ModelExplorer);
if (readOnlyAttribute != null && !inputTagHelperOutput.Attributes.ContainsName("readonly"))
{
inputTagHelperOutput.Attributes.Add("readonly", "");
}
}
protected virtual bool IsInputCheckbox(TagHelperContext context, TagHelperOutput output, TagHelperAttributeList attributes)

@ -71,10 +71,21 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
var inputTagHelperOutput = GetInnerTagHelper(new TagHelperAttributeList(), context, selectTagHelper, "select", TagMode.StartTagAndEndTag);
inputTagHelperOutput.Attributes.Add("class", "form-control");
AddDisabledAttribute(inputTagHelperOutput);
return inputTagHelperOutput;
}
protected virtual void AddDisabledAttribute(TagHelperOutput inputTagHelperOutput)
{
var disabledAttribute = GetAttribute<DisabledInput>(TagHelper.AspFor.ModelExplorer);
if (disabledAttribute != null && !inputTagHelperOutput.Attributes.ContainsName("disabled"))
{
inputTagHelperOutput.Attributes.Add("disabled", "");
}
}
protected virtual List<SelectListItem> GetSelectItems(TagHelperContext context, TagHelperOutput output)
{
var selectItems = TagHelper.AspItems?.ToList();

@ -0,0 +1,15 @@
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 DisabledInput : Attribute
{
public DisabledInput()
{
}
}
}

@ -0,0 +1,15 @@
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 ReadOnlyInput : Attribute
{
public ReadOnlyInput()
{
}
}
}
Loading…
Cancel
Save