Merge pull request #3737 from liangshiw/liangshiwei/tag-helpers-dynamic-form

Remove FormGroupItem that are not in the model
pull/3760/head
Yunus Emre Kalkan 5 years ago committed by GitHub
commit e6d7de9c3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -43,6 +43,8 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
await ProcessFieldsAsync(context, output);
RemoveFormGroupItemsNotInModel(context, output, list);
SetContent(context, output, list, childContent);
SetFormAttributes(context, output);
@ -143,6 +145,14 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
}
}
protected virtual void RemoveFormGroupItemsNotInModel(TagHelperContext context, TagHelperOutput output, List<FormGroupItem> items)
{
var models = GetModels(context, output);
items.RemoveAll(x => models.All(m => !m.Name.Equals(x.PropertyName, StringComparison.InvariantCultureIgnoreCase)));
}
protected virtual async Task ProcessSelectGroupAsync(TagHelperContext context, TagHelperOutput output, ModelExpression model)
{
var abpSelectTagHelper = GetSelectGroupTagHelper(context, output, model);
@ -152,7 +162,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
protected virtual AbpTagHelper GetSelectGroupTagHelper(TagHelperContext context, TagHelperOutput output, ModelExpression model)
{
return IsRadioGroup(model.ModelExplorer) ?
return IsRadioGroup(model.ModelExplorer) ?
GetAbpRadioInputTagHelper(model) :
GetSelectTagHelper(model);
}

@ -58,7 +58,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
protected virtual async Task<(string, bool)> GetFormInputGroupAsHtmlAsync(TagHelperContext context, TagHelperOutput output)
{
var (inputTag, isCheckBox) = await GetInputTagHelperOutputAsync(context, output);
var inputHtml = inputTag.Render(_encoder);
var label = await GetLabelAsHtmlAsync(context, output, inputTag, isCheckBox);
var info = GetInfoAsHtml(context, output, inputTag, isCheckBox);
@ -161,7 +161,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
protected virtual void AddDisabledAttribute(TagHelperOutput inputTagHelperOutput)
{
if (inputTagHelperOutput.Attributes.ContainsName("disabled") == false &&
if (inputTagHelperOutput.Attributes.ContainsName("disabled") == false &&
(TagHelper.IsDisabled || TagHelper.AspFor.ModelExplorer.GetAttribute<DisabledInput>() != null))
{
inputTagHelperOutput.Attributes.Add("disabled", "");
@ -170,7 +170,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
protected virtual void AddReadOnlyAttribute(TagHelperOutput inputTagHelperOutput)
{
if (inputTagHelperOutput.Attributes.ContainsName("readonly") == false &&
if (inputTagHelperOutput.Attributes.ContainsName("readonly") == false &&
(TagHelper.IsReadonly != false || TagHelper.AspFor.ModelExplorer.GetAttribute<ReadOnlyInput>() != null))
{
inputTagHelperOutput.Attributes.Add("readonly", "");
@ -400,9 +400,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
list.Add(new FormGroupItem
{
HtmlContent = html,
Order = order
Order = order,
PropertyName = propertyName
});
}
}
}
}
}

@ -167,9 +167,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
list.Add(new FormGroupItem
{
HtmlContent = html,
Order = order
Order = order,
PropertyName = propertyName
});
}
}
}
}
}

@ -125,7 +125,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
return await GetLabelAsHtmlUsingTagHelperAsync(context, output) + GetRequiredSymbol(context, output);
}
protected virtual string GetRequiredSymbol(TagHelperContext context, TagHelperOutput output)
{
if (!TagHelper.DisplayRequiredSymbol)
@ -221,7 +221,7 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
}
protected virtual List<SelectListItem> GetSelectItemsFromAttribute(
SelectItems selectItemsAttribute,
SelectItems selectItemsAttribute,
ModelExplorer explorer)
{
var selectItems = selectItemsAttribute.GetItems(explorer)?.ToList();
@ -329,9 +329,10 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
list.Add(new FormGroupItem
{
HtmlContent = html,
Order = order
Order = order,
PropertyName = propertyName
});
}
}
}
}
}

@ -5,5 +5,7 @@
public string HtmlContent { get; set; }
public int Order { get; set; }
public string PropertyName { get; set; }
}
}
Loading…
Cancel
Save