Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ public partial class EditorForm<TModel> : IShowLabel, IDisposable
public int? LabelWidth { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 列模板 设置 <see cref="Items"/> 时本参数不生效</para>
/// <para lang="en">Gets or sets Field Items Template. Not effective when <see cref="Items"/> is set</para>
/// <para lang="zh">获得/设置 绑定属性集合模板 设置 <see cref="Items"/> 时本参数优先级高</para>
/// <para lang="en">Gets or sets the field items collection template.</para>
Comment thread
ArgoZhang marked this conversation as resolved.
/// </summary>
[Parameter]
public RenderFragment<TModel>? FieldItems { get; set; }
Expand Down Expand Up @@ -158,8 +158,8 @@ public partial class EditorForm<TModel> : IShowLabel, IDisposable
public List<string>? IgnoreItems { get; set; }

/// <summary>
/// <para lang="zh">获得/设置 级联上下文绑定字段信息集合 设置此参数后 <see cref="FieldItems"/> 模板不生效</para>
/// <para lang="en">Gets or sets Context Field Items Collection. <see cref="FieldItems"/> template will not be effective if set</para>
/// <para lang="zh">获得/设置 绑定字段信息集合 设置此参数后 <see cref="FieldItems"/> 模板优先级更高</para>
/// <para lang="en">Gets or sets the items collection.</para>
Comment thread
ArgoZhang marked this conversation as resolved.
/// </summary>
[Parameter]
public IEnumerable<IEditorItem>? Items { get; set; }
Expand Down Expand Up @@ -294,7 +294,8 @@ private List<IEditorItem> GetRenderItems()
var items = new List<IEditorItem>();
if (Items != null)
{
items.AddRange(Items.Where(i => !i.GetIgnore() && !string.IsNullOrEmpty(i.GetFieldName()) && FilterIgnoreItem(i)));
items.AddRange(Items.Where(i => _editorItems.Find(item => i.GetFieldName() == item.GetFieldName()) == null && FilterEditorItem(i)));
Comment thread
ArgoZhang marked this conversation as resolved.
Outdated
items.AddRange(_editorItems.Where(FilterEditorItem));
return items;
}

Expand All @@ -309,6 +310,8 @@ private List<IEditorItem> GetRenderItems()
return items;
}

private bool FilterEditorItem(IEditorItem i) => !i.GetIgnore() && !string.IsNullOrEmpty(i.GetFieldName()) && FilterIgnoreItem(i);

private bool FilterIgnoreItem(IEditorItem item)
{
return IgnoreItems?.Find(i => i.Equals(item.GetFieldName(), StringComparison.OrdinalIgnoreCase)) == null;
Expand Down
21 changes: 21 additions & 0 deletions test/UnitTest/Components/EditorFormTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,29 @@ public void Items_Ok()
pb.Add(a => a.Items, new List<IEditorItem>
{
new InternalTableColumn("Id", typeof(int)) { Ignore = true },
new InternalTableColumn("Name", typeof(string)),
new TableTemplateColumn<Foo>()
});

pb.Add(a => a.FieldItems, f => builder =>
{
var index = 0;
builder.OpenComponent<EditorItem<Foo, string>>(index++);
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.Field), f.Name);
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.FieldExpression), Utility.GenerateValueExpression(foo, nameof(Foo.Name), typeof(string)));

builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.Required), true);
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.RequiredErrorMessage), "Test");
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.Readonly), true);
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.SkipValidate), false);
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.Text), "Test-Text");
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.ComponentType), typeof(BootstrapInput<string>));
builder.AddAttribute(index++, nameof(EditorItem<Foo, string>.ComponentParameters), new KeyValuePair<string, object>[]
Comment thread
ArgoZhang marked this conversation as resolved.
{
new("type", "text")
});
builder.CloseComponent();
});
});
Comment thread
ArgoZhang marked this conversation as resolved.
}

Expand Down
Loading