Browse Source

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 7 years ago
committed by GitHub
parent
commit
e6d7de9c3f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpDynamicformTagHelperService.cs
  2. 11
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpInputTagHelperService.cs
  3. 5
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpRadioInputTagHelperService.cs
  4. 9
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpSelectTagHelperService.cs
  5. 2
      framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/FormGroupItem.cs

12
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/AbpDynamicformTagHelperService.cs

@ -43,6 +43,8 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
await ProcessFieldsAsync(context, output); await ProcessFieldsAsync(context, output);
RemoveFormGroupItemsNotInModel(context, output, list);
SetContent(context, output, list, childContent); SetContent(context, output, list, childContent);
SetFormAttributes(context, output); 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) protected virtual async Task ProcessSelectGroupAsync(TagHelperContext context, TagHelperOutput output, ModelExpression model)
{ {
var abpSelectTagHelper = GetSelectGroupTagHelper(context, output, 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) protected virtual AbpTagHelper GetSelectGroupTagHelper(TagHelperContext context, TagHelperOutput output, ModelExpression model)
{ {
return IsRadioGroup(model.ModelExplorer) ? return IsRadioGroup(model.ModelExplorer) ?
GetAbpRadioInputTagHelper(model) : GetAbpRadioInputTagHelper(model) :
GetSelectTagHelper(model); GetSelectTagHelper(model);
} }

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

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

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

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

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

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

2
framework/src/Volo.Abp.AspNetCore.Mvc.UI.Bootstrap/TagHelpers/Form/FormGroupItem.cs

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