Browse Source

abp input readonly improvements

pull/670/head
Yunus Emre Kalkan 8 years ago
parent
commit
c3be3c3004
  1. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs
  2. 35
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs
  3. 9
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpReadonlyInputType.cs
  4. 7
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/ReadOnlyInput.cs

2
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; }

35
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<ReadOnlyInput>(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<DisabledInput>(TagHelper.AspFor.ModelExplorer) != null)
if (inputTagHelperOutput.Attributes.ContainsName("disabled") == false &&
(TagHelper.IsDisabled || GetAttribute<DisabledInput>(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<ReadOnlyInput>(TagHelper.AspFor.ModelExplorer) != null)
if (inputTagHelperOutput.Attributes.ContainsName("readonly") == false &&
(TagHelper.IsReadonly != AbpReadonlyInputType.False || GetAttribute<ReadOnlyInput>(TagHelper.AspFor.ModelExplorer) != null))
{
inputTagHelperOutput.Attributes.Add("readonly", "");
}

9
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
}
}

7
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;
}
}
}

Loading…
Cancel
Save