Dynamic-form: Allow to remove required symbol

https://github.com/abpframework/abp/issues/689
pull/696/head
Yunus Emre Kalkan 7 years ago
parent 89fbb9e23f
commit 3fd67a46c3

@ -18,6 +18,8 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
public bool? SubmitButton { get; set; } public bool? SubmitButton { get; set; }
public bool? RequiredSymbols { get; set; } = true;
#region MvcFormTagHelperAttiributes #region MvcFormTagHelperAttiributes
private const string ActionAttributeName = "asp-action"; private const string ActionAttributeName = "asp-action";

@ -192,6 +192,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
var abpInputTagHelper = _serviceProvider.GetRequiredService<AbpInputTagHelper>(); var abpInputTagHelper = _serviceProvider.GetRequiredService<AbpInputTagHelper>();
abpInputTagHelper.AspFor = model; abpInputTagHelper.AspFor = model;
abpInputTagHelper.ViewContext = TagHelper.ViewContext; abpInputTagHelper.ViewContext = TagHelper.ViewContext;
abpInputTagHelper.DisplayRequiredSymbol = TagHelper.RequiredSymbols ?? true;
RenderTagHelper(new TagHelperAttributeList(), context, abpInputTagHelper, _htmlEncoder, "div", TagMode.StartTagAndEndTag); RenderTagHelper(new TagHelperAttributeList(), context, abpInputTagHelper, _htmlEncoder, "div", TagMode.StartTagAndEndTag);
} }

@ -23,6 +23,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
public AbpFormControlSize Size { get; set; } = AbpFormControlSize.Default; public AbpFormControlSize Size { get; set; } = AbpFormControlSize.Default;
[HtmlAttributeNotBound]
public bool DisplayRequiredSymbol { get; set; } = true;
[HtmlAttributeNotBound] [HtmlAttributeNotBound]
[ViewContext] [ViewContext]
public ViewContext ViewContext { get; set; } public ViewContext ViewContext { get; set; }

@ -61,7 +61,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
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) + GetRequiredSymbol(context, output, inputTag); 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);
@ -242,19 +242,19 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
if (string.IsNullOrEmpty(TagHelper.Label)) if (string.IsNullOrEmpty(TagHelper.Label))
{ {
return GetLabelAsHtmlUsingTagHelper(context, output, isCheckbox); return GetLabelAsHtmlUsingTagHelper(context, output, isCheckbox) + GetRequiredSymbol(context, output, inputTag);
} }
var checkboxClass = isCheckbox ? "class=\"form-check-label\" " : ""; var checkboxClass = isCheckbox ? "class=\"form-check-label\" " : "";
return "<label " + checkboxClass + GetIdAttributeAsString(inputTag) + ">" return "<label " + checkboxClass + GetIdAttributeAsString(inputTag) + ">"
+ TagHelper.Label + + TagHelper.Label +
"</label>"; "</label>" + GetRequiredSymbol(context, output, inputTag);
} }
protected virtual string GetRequiredSymbol(TagHelperContext context, TagHelperOutput output, TagHelperOutput inputTag) protected virtual string GetRequiredSymbol(TagHelperContext context, TagHelperOutput output, TagHelperOutput inputTag)
{ {
if (IsOutputHidden(inputTag)) if (!TagHelper.DisplayRequiredSymbol)
{ {
return ""; return "";
} }

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

@ -57,7 +57,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
{ {
var selectTag = GetSelectTag(context, output); var selectTag = GetSelectTag(context, output);
var selectAsHtml = RenderTagHelperOutput(selectTag, _encoder); var selectAsHtml = RenderTagHelperOutput(selectTag, _encoder);
var label = GetLabelAsHtml(context, output, selectTag) + GetRequiredSymbol(context, output); var label = GetLabelAsHtml(context, output, selectTag);
var validation = GetValidationAsHtml(context, output, selectTag); var validation = GetValidationAsHtml(context, output, selectTag);
var infoText = GetInfoAsHtml(context, output, selectTag); var infoText = GetInfoAsHtml(context, output, selectTag);
@ -116,15 +116,20 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
{ {
if (!string.IsNullOrEmpty(TagHelper.Label)) if (!string.IsNullOrEmpty(TagHelper.Label))
{ {
return "<label " + GetIdAttributeAsString(selectTag) + ">" + TagHelper.Label + "</label>"; return "<label " + GetIdAttributeAsString(selectTag) + ">" + TagHelper.Label + "</label>" + GetRequiredSymbol(context, output);
} }
return GetLabelAsHtmlUsingTagHelper(context, output); return GetLabelAsHtmlUsingTagHelper(context, output) + GetRequiredSymbol(context, output);
} }
protected virtual string GetRequiredSymbol(TagHelperContext context, TagHelperOutput output) protected virtual string GetRequiredSymbol(TagHelperContext context, TagHelperOutput output)
{ {
if (!TagHelper.DisplayRequiredSymbol)
{
return "";
}
return GetAttribute<RequiredAttribute>(TagHelper.AspFor.ModelExplorer) != null ? "<span> (*) </span>" : ""; return GetAttribute<RequiredAttribute>(TagHelper.AspFor.ModelExplorer) != null ? "<span> (*) </span>" : "";
} }

@ -30,7 +30,7 @@
<div class="demo-with-code"> <div class="demo-with-code">
<div class="demo-area"> <div class="demo-area">
<abp-dynamic-form abp-model="@Model.MyDetailedModel" submit-button="true" /> <abp-dynamic-form abp-model="@Model.MyDetailedModel" submit-button="true"/>
</div> </div>
<div class="code-area"> <div class="code-area">
<abp-tabs> <abp-tabs>

Loading…
Cancel
Save