pull/279/head
Halil İbrahim Kalkan 7 years ago
commit a8174f220e

@ -33,7 +33,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var list = InitilizeFormGroupContentsContext(context);
var list = InitilizeFormGroupContentsContext(context, output);
NormalizeTagMode(context, output);
@ -43,9 +43,9 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
ProcessFields(context, output);
SetContent(output,list);
SetContent(output, list);
SetFormAttributes(output);
SetFormAttributes(context, output);
SetSubmitButton(context, output);
}
@ -81,7 +81,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
output.TagName = "form";
}
protected virtual void SetFormAttributes(TagHelperOutput output)
protected virtual void SetFormAttributes(TagHelperContext context, TagHelperOutput output)
{
output.Attributes.AddIfNotContains("method", "post");
}
@ -110,7 +110,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
output.PostContent.SetHtmlContent(output.PostContent.GetContent() + buttonHtml);
}
protected virtual List<FormGroupItem> InitilizeFormGroupContentsContext(TagHelperContext context)
protected virtual List<FormGroupItem> InitilizeFormGroupContentsContext(TagHelperContext context, TagHelperOutput output)
{
var items = new List<FormGroupItem>();
context.Items[FormGroupContents] = items;
@ -125,15 +125,15 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
{
if (IsSelectGroup(context, model))
{
ProcessSelectGroup(context, model);
ProcessSelectGroup(context, output, model);
continue;
}
ProcessInputGroup(context, model);
ProcessInputGroup(context, output, model);
}
}
protected virtual void ProcessSelectGroup(TagHelperContext context, ModelExpression model)
protected virtual void ProcessSelectGroup(TagHelperContext context, TagHelperOutput output, ModelExpression model)
{
var abpSelectTagHelper = _serviceProvider.GetRequiredService<AbpSelectTagHelper>();
abpSelectTagHelper.AspFor = model;
@ -154,7 +154,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
return RenderTagHelper(attributes, context, abpButtonTagHelper, _htmlEncoder, "button", TagMode.StartTagAndEndTag);
}
protected virtual void ProcessInputGroup(TagHelperContext context, ModelExpression model)
protected virtual void ProcessInputGroup(TagHelperContext context, TagHelperOutput output, ModelExpression model)
{
var abpInputTagHelper = _serviceProvider.GetRequiredService<AbpInputTagHelper>();
abpInputTagHelper.AspFor = model;

@ -30,7 +30,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
var order = GetInputOrder(TagHelper.AspFor.ModelExplorer);
AddGroupToFormGroupContents(context, TagHelper.AspFor.Name, SurroundInnerHtmlAndGet(innerHtml, isCheckbox), order, out var surpress);
AddGroupToFormGroupContents(context, TagHelper.AspFor.Name, SurroundInnerHtmlAndGet(context, output, innerHtml, isCheckbox), order, out var surpress);
if (surpress)
{
@ -47,15 +47,15 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
protected virtual string GetFormInputGroupAsHtml(TagHelperContext context, TagHelperOutput output, out bool isCheckbox)
{
var inputTag = GetInputTag(context, out isCheckbox);
var inputTag = GetInputTag(context, output, out isCheckbox);
var inputHtml = RenderTagHelperOutput(inputTag, _encoder);
var label = GetLabelAsHtml(inputTag, isCheckbox);
var label = GetLabelAsHtml(context, output, inputTag, isCheckbox);
var validation = isCheckbox ? "" : GetValidationAsHtml(context);
var validation = isCheckbox ? "" : GetValidationAsHtml(context, output);
return GetContent(label, inputHtml, validation, isCheckbox);
return GetContent(context, output, label, inputHtml, validation, isCheckbox);
}
protected virtual string GetValidationAsHtml(TagHelperContext context)
protected virtual string GetValidationAsHtml(TagHelperContext context, TagHelperOutput output)
{
var validationMessageTagHelper = new ValidationMessageTagHelper(_generator)
{
@ -68,7 +68,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
return RenderTagHelper(attributeList, context, validationMessageTagHelper, _encoder, "span", TagMode.StartTagAndEndTag, true);
}
protected virtual string GetContent(string label, string inputHtml, string validation, bool isCheckbox)
protected virtual string GetContent(TagHelperContext context, TagHelperOutput output, string label, string inputHtml, string validation, bool isCheckbox)
{
var innerContent = isCheckbox ?
inputHtml + Environment.NewLine + label :
@ -78,14 +78,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
Environment.NewLine + validation + Environment.NewLine;
}
protected virtual string SurroundInnerHtmlAndGet(string innerHtml, bool isCheckbox)
protected virtual string SurroundInnerHtmlAndGet(TagHelperContext context, TagHelperOutput output, string innerHtml, bool isCheckbox)
{
return "<div class=\"" + (isCheckbox ? "form-check" : "form-group") + "\">" +
Environment.NewLine + innerHtml + Environment.NewLine +
"</div>";
}
protected virtual TagHelperOutput GetInputTag(TagHelperContext context, out bool isCheckbox)
protected virtual TagHelperOutput GetInputTag(TagHelperContext context, TagHelperOutput output, out bool isCheckbox)
{
var inputTagHelper = new InputTagHelper(_generator)
{
@ -94,19 +94,19 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
};
var inputTagHelperOutput = GetInnerTagHelper(new TagHelperAttributeList(), context, inputTagHelper, "input");
isCheckbox = IsInputCheckbox(inputTagHelperOutput.Attributes);
isCheckbox = IsInputCheckbox(context, output,inputTagHelperOutput.Attributes);
inputTagHelperOutput.Attributes.Add("class", isCheckbox ? "form-check-input" : "form-control");
return inputTagHelperOutput;
}
protected virtual bool IsInputCheckbox(TagHelperAttributeList attributes)
protected virtual bool IsInputCheckbox(TagHelperContext context, TagHelperOutput output, TagHelperAttributeList attributes)
{
return attributes.Any(a => a.Value != null && a.Name == "type" && a.Value.ToString() == "checkbox");
}
protected virtual string GetLabelAsHtml(TagHelperOutput inputTag, bool isCheckbox)
protected virtual string GetLabelAsHtml(TagHelperContext context, TagHelperOutput output, TagHelperOutput inputTag, bool isCheckbox)
{
if (string.IsNullOrEmpty(TagHelper.Label) && string.IsNullOrEmpty(TagHelper.AspFor.Metadata.DisplayName))
{
@ -116,11 +116,11 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
var checkboxClass = isCheckbox ? "class=\"form-check-label\" " : "";
return "<label " + checkboxClass + GetIdAttributeAsString(inputTag) + ">"
+ GetLabelValue() +
+ GetLabelValue(context,output) +
"</label>";
}
protected virtual string GetLabelValue()
protected virtual string GetLabelValue(TagHelperContext context, TagHelperOutput output)
{
return string.IsNullOrEmpty(TagHelper.Label) ?
TagHelper.AspFor.Metadata.DisplayName :

@ -32,7 +32,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
var order = GetInputOrder(TagHelper.AspFor.ModelExplorer);
AddGroupToFormGroupContents(context, TagHelper.AspFor.Name, SurroundInnerHtmlAndGet(innerHtml), order, out var surpress);
AddGroupToFormGroupContents(context, TagHelper.AspFor.Name, SurroundInnerHtmlAndGet(context, output, innerHtml), order, out var surpress);
if (surpress)
{
@ -49,28 +49,21 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
protected virtual string GetFormInputGroupAsHtml(TagHelperContext context, TagHelperOutput output)
{
var selectTag = GetSelectTag(context);
var selectTag = GetSelectTag(context, output);
var selectAsHtml = RenderTagHelperOutput(selectTag, _encoder);
var label = GetLabelAsHtml(selectTag);
var label = GetLabelAsHtml(context, output, selectTag);
return label + Environment.NewLine + selectAsHtml;
}
protected virtual string SurroundInnerHtmlAndGet(string innerHtml)
protected virtual string SurroundInnerHtmlAndGet(TagHelperContext context, TagHelperOutput output, string innerHtml)
{
return "<div class=\"form-group\">" + Environment.NewLine + innerHtml + Environment.NewLine + "</div>";
}
protected virtual TagHelperOutput GetSelectTag(TagHelperContext context)
protected virtual TagHelperOutput GetSelectTag(TagHelperContext context, TagHelperOutput output)
{
var selectItems = TagHelper.AspItems?.ToList();
if (TagHelper.AspItems == null && !GetSelectItemsIfProvidedByEnum(TagHelper.AspFor.ModelExplorer, out selectItems) && !GetSelectItemsIfProvidedFromAttribute(TagHelper.AspFor.ModelExplorer, out selectItems))
{
throw new Exception("No items provided for select attribute.");
}
SetSelectedValue(selectItems);
var selectItems = GetSelectItems(context, output);
var selectTagHelper = new SelectTagHelper(_generator)
{
@ -79,14 +72,28 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
ViewContext = TagHelper.ViewContext
};
var inputTagHelperOutput = GetInnerTagHelper(new TagHelperAttributeList(), context, selectTagHelper, "select", TagMode.StartTagAndEndTag); ;
var inputTagHelperOutput = GetInnerTagHelper(new TagHelperAttributeList(), context, selectTagHelper, "select", TagMode.StartTagAndEndTag);
inputTagHelperOutput.Attributes.Add("class", "form-control");
return inputTagHelperOutput;
}
protected virtual string GetLabelAsHtml(TagHelperOutput selectTag)
protected virtual List<SelectListItem> GetSelectItems(TagHelperContext context, TagHelperOutput output)
{
var selectItems = TagHelper.AspItems?.ToList();
if (TagHelper.AspItems == null && !GetSelectItemsIfProvidedByEnum(context, output, TagHelper.AspFor.ModelExplorer, out selectItems) && !GetSelectItemsIfProvidedFromAttribute(context, output, TagHelper.AspFor.ModelExplorer, out selectItems))
{
throw new Exception("No items provided for select attribute.");
}
SetSelectedValue(context, output, selectItems);
return selectItems;
}
protected virtual string GetLabelAsHtml(TagHelperContext context, TagHelperOutput output, TagHelperOutput selectTag)
{
if (string.IsNullOrEmpty(TagHelper.Label) && string.IsNullOrEmpty(TagHelper.AspFor.Metadata.DisplayName))
{
@ -103,7 +110,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
TagHelper.Label;
}
protected virtual bool GetSelectItemsIfProvidedByEnum(ModelExplorer explorer, out List<SelectListItem> selectItems)
protected virtual bool GetSelectItemsIfProvidedByEnum(TagHelperContext context, TagHelperOutput output, ModelExplorer explorer, out List<SelectListItem> selectItems)
{
selectItems = explorer.Metadata.IsEnum ? explorer.ModelType.GetTypeInfo().GetMembers(BindingFlags.Public | BindingFlags.Static)
.Select((t, i) => new SelectListItem { Value = i.ToString(), Text = t.Name }).ToList() : null;
@ -111,16 +118,16 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
return selectItems != null;
}
protected virtual bool GetSelectItemsIfProvidedFromAttribute(ModelExplorer explorer, out List<SelectListItem> selectItems)
protected virtual bool GetSelectItemsIfProvidedFromAttribute(TagHelperContext context, TagHelperOutput output, ModelExplorer explorer, out List<SelectListItem> selectItems)
{
selectItems = GetAttribute<SelectItems>(explorer)?.GetItems(explorer, explorer.Model.ToString())?.ToList();
return selectItems != null;
}
protected virtual void SetSelectedValue(List<SelectListItem> selectItems)
protected virtual void SetSelectedValue(TagHelperContext context, TagHelperOutput output, List<SelectListItem> selectItems)
{
var selectedValue = GetSelectedValue();
var selectedValue = GetSelectedValue(context, output);
if (!selectItems.Any(si => si.Selected))
{
@ -133,7 +140,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
}
}
protected virtual string GetSelectedValue()
protected virtual string GetSelectedValue(TagHelperContext context, TagHelperOutput output)
{
if (TagHelper.AspFor.ModelExplorer.Metadata.IsEnum)
{

Loading…
Cancel
Save