Browse Source

Seelct Tag helper info text

pull/676/head
Yunus Emre Kalkan 8 years ago
parent
commit
77d1ffccde
  1. 3
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs
  2. 37
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs
  3. 1
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpRadioInputTagHelperService.cs
  4. 3
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs
  5. 72
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs

3
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelper.cs

@ -10,6 +10,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
public string Label { get; set; } public string Label { get; set; }
[HtmlAttributeName("info")]
public string InfoText { get; set; }
[HtmlAttributeName("disabled")] [HtmlAttributeName("disabled")]
public bool IsDisabled { get; set; } = false; public bool IsDisabled { get; set; } = false;

37
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs

@ -58,10 +58,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
protected virtual string GetFormInputGroupAsHtml(TagHelperContext context, TagHelperOutput output, out bool isCheckbox) protected virtual string GetFormInputGroupAsHtml(TagHelperContext context, TagHelperOutput output, out bool isCheckbox)
{ {
var inputTag = GetInputTagHelperOutput(context, output, out isCheckbox); var inputTag = GetInputTagHelperOutput(context, output, out isCheckbox);
var inputHtml = RenderTagHelperOutput(inputTag, _encoder); var inputHtml = RenderTagHelperOutput(inputTag, _encoder);
var label = GetLabelAsHtml(context, output, inputTag, isCheckbox); var label = GetLabelAsHtml(context, output, inputTag, isCheckbox);
var info = GetInfoAsHtml(context, output, inputTag, isCheckbox); var info = GetInfoAsHtml(context, output, inputTag, isCheckbox);
var validation = isCheckbox ? "" : GetValidationAsHtml(context, output, inputTag); var validation = isCheckbox ? "" : GetValidationAsHtml(context, output, inputTag);
return GetContent(context, output, label, inputHtml, validation, info, isCheckbox); return GetContent(context, output, label, inputHtml, validation, info, isCheckbox);
@ -88,11 +88,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
protected virtual string GetContent(TagHelperContext context, TagHelperOutput output, string label, string inputHtml, string validation, string infoHtml, bool isCheckbox) protected virtual string GetContent(TagHelperContext context, TagHelperOutput output, string label, string inputHtml, string validation, string infoHtml, bool isCheckbox)
{ {
var innerContent = isCheckbox ? var innerContent = isCheckbox ?
inputHtml + Environment.NewLine + label : inputHtml + label :
label + Environment.NewLine + inputHtml; label + inputHtml;
return Environment.NewLine + innerContent + Environment.NewLine + return innerContent + infoHtml + validation;
Environment.NewLine + validation + Environment.NewLine + infoHtml;
} }
protected virtual string SurroundInnerHtmlAndGet(TagHelperContext context, TagHelperOutput output, string innerHtml, bool isCheckbox) protected virtual string SurroundInnerHtmlAndGet(TagHelperContext context, TagHelperOutput output, string innerHtml, bool isCheckbox)
@ -259,23 +258,29 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
return ""; return "";
} }
var infoAttribute = GetAttribute<InputInfoText>(TagHelper.AspFor.ModelExplorer); string text = "";
if (infoAttribute == null)
if (!string.IsNullOrEmpty(TagHelper.InfoText))
{ {
return ""; text = TagHelper.InfoText;
} }
else
var idAttr = inputTag.Attributes.FirstOrDefault(a => a.Name == "id");
if (idAttr == null)
{ {
return ""; var infoAttribute = GetAttribute<InputInfoText>(TagHelper.AspFor.ModelExplorer);
if (infoAttribute != null)
{
text = infoAttribute.Text;
}
else
{
return "";
}
} }
var id = idAttr.Value + "InfoText"; var idAttr = inputTag.Attributes.FirstOrDefault(a => a.Name == "id");
return "<small id=\""+ id + "\" class=\"form-text text-muted\">" + return "<small id=\""+ idAttr?.Value + "InfoText\" class=\"form-text text-muted\">" +
LocalizeText(infoAttribute.Text) + LocalizeText(text) +
"</small>"; "</small>";
} }

1
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpRadioInputTagHelperService.cs

@ -31,7 +31,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
var html = GetHtml(context, output, selectItems); var html = GetHtml(context, output, selectItems);
AddGroupToFormGroupContents(context, TagHelper.AspFor.Name, html, order, out var surpress); AddGroupToFormGroupContents(context, TagHelper.AspFor.Name, html, order, out var surpress);
if (surpress) if (surpress)

3
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelper.cs

@ -15,6 +15,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
public AbpFormControlSize Size { get; set; } = AbpFormControlSize.Default; public AbpFormControlSize Size { get; set; } = AbpFormControlSize.Default;
[HtmlAttributeName("info")]
public string InfoText { get; set; }
[HtmlAttributeNotBound] [HtmlAttributeNotBound]
[ViewContext] [ViewContext]
public ViewContext ViewContext { get; set; } public ViewContext ViewContext { get; set; }

72
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs

@ -58,8 +58,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
var selectAsHtml = RenderTagHelperOutput(selectTag, _encoder); var selectAsHtml = RenderTagHelperOutput(selectTag, _encoder);
var label = GetLabelAsHtml(context, output, selectTag); var label = GetLabelAsHtml(context, output, selectTag);
var validation = GetValidationAsHtml(context, output, selectTag); var validation = GetValidationAsHtml(context, output, selectTag);
var infoText = GetInfoAsHtml(context, output, selectTag);
return label + Environment.NewLine + selectAsHtml + Environment.NewLine + validation; return label + Environment.NewLine + selectAsHtml + Environment.NewLine + infoText+ Environment.NewLine + validation;
} }
protected virtual string SurroundInnerHtmlAndGet(TagHelperContext context, TagHelperOutput output, string innerHtml) protected virtual string SurroundInnerHtmlAndGet(TagHelperContext context, TagHelperOutput output, string innerHtml)
@ -76,13 +77,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
ViewContext = TagHelper.ViewContext ViewContext = TagHelper.ViewContext
}; };
var inputTagHelperOutput = GetInnerTagHelper(GetInputAttributes(context, output), context, selectTagHelper, "select", TagMode.StartTagAndEndTag); var selectTagHelperOutput = GetInnerTagHelper(GetInputAttributes(context, output), context, selectTagHelper, "select", TagMode.StartTagAndEndTag);
inputTagHelperOutput.Attributes.AddClass("form-control"); selectTagHelperOutput.Attributes.AddClass("form-control");
inputTagHelperOutput.Attributes.AddClass(GetSize(context,output)); selectTagHelperOutput.Attributes.AddClass(GetSize(context,output));
AddDisabledAttribute(inputTagHelperOutput); AddDisabledAttribute(selectTagHelperOutput);
AddInfoTextId(selectTagHelperOutput);
return inputTagHelperOutput; return selectTagHelperOutput;
} }
protected virtual void AddDisabledAttribute(TagHelperOutput inputTagHelperOutput) protected virtual void AddDisabledAttribute(TagHelperOutput inputTagHelperOutput)
@ -119,6 +121,64 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
return GetLabelAsHtmlUsingTagHelper(context, output); return GetLabelAsHtmlUsingTagHelper(context, output);
} }
protected virtual void AddInfoTextId(TagHelperOutput inputTagHelperOutput)
{
if (GetAttribute<InputInfoText>(TagHelper.AspFor.ModelExplorer) == null)
{
return;
}
var idAttr = inputTagHelperOutput.Attributes.FirstOrDefault(a => a.Name == "id");
if (idAttr == null)
{
return;
}
inputTagHelperOutput.Attributes.Add("aria-describedby", LocalizeText(idAttr.Value + "InfoText"));
}
protected virtual string GetInfoAsHtml(TagHelperContext context, TagHelperOutput output, TagHelperOutput inputTag)
{
string text = "";
if (!string.IsNullOrEmpty(TagHelper.InfoText))
{
text = TagHelper.InfoText;
}
else
{
var infoAttribute = GetAttribute<InputInfoText>(TagHelper.AspFor.ModelExplorer);
if (infoAttribute != null)
{
text = infoAttribute.Text;
}
else
{
return "";
}
}
var idAttr = inputTag.Attributes.FirstOrDefault(a => a.Name == "id");
return "<small id=\"" + idAttr?.Value + "InfoText\" class=\"form-text text-muted\">" +
LocalizeText(text) +
"</small>";
}
protected virtual string LocalizeText(string text)
{
IStringLocalizer localizer = null;
var resourceType = _options.AssemblyResources.GetOrDefault(TagHelper.AspFor.ModelExplorer.ModelType.Assembly);
if (resourceType != null)
{
localizer = _stringLocalizerFactory.Create(resourceType);
}
return localizer == null ? text : localizer[text].Value;
}
protected virtual bool GetSelectItemsIfProvidedByEnum(TagHelperContext context, TagHelperOutput output, ModelExplorer explorer, out List<SelectListItem> selectItems) protected virtual bool GetSelectItemsIfProvidedByEnum(TagHelperContext context, TagHelperOutput output, ModelExplorer explorer, out List<SelectListItem> selectItems)
{ {
IStringLocalizer localizer = null; IStringLocalizer localizer = null;

Loading…
Cancel
Save