Skip to content

Commit e957946

Browse files
authored
feat(Table): skip validate on Excel model (#6017)
* refactor: Table Excel 模式禁止 Validate * test: 更新单元测试 * chore: bump version 9.6.2-beta04
1 parent 316eca5 commit e957946

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.6.2-beta03</Version>
4+
<Version>9.6.2-beta04</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Table/Table.razor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ RenderFragment RenderTemplate() => col.Template == null
13401340
: col.Template(item);
13411341

13421342
RenderFragment RenderEditTemplate() => col.EditTemplate == null
1343-
? new RenderFragment(builder => builder.CreateComponentByFieldType(this, col, item, changedType, false, col.GetLookupService(InjectLookupService)))
1343+
? new RenderFragment(builder => builder.CreateComponentByFieldType(this, col, item, changedType, isSearch: false, col.GetLookupService(InjectLookupService), skipValidate: true))
13441344
: col.EditTemplate(item);
13451345
}
13461346

@@ -1382,7 +1382,7 @@ void SetDynamicEditTemplate()
13821382
parameters.Add(new(nameof(ValidateBase<string>.OnValueChanged), onValueChanged.Invoke(d, col, (model, column, val) => DynamicContext.OnValueChanged(model, column, val))));
13831383
col.ComponentParameters = parameters;
13841384
}
1385-
builder.CreateComponentByFieldType(this, col, row, changedType, false, col.GetLookupService(InjectLookupService));
1385+
builder.CreateComponentByFieldType(this, col, row, changedType, false, col.GetLookupService(InjectLookupService), skipValidate: true);
13861386
};
13871387
}
13881388

src/BootstrapBlazor/Utils/Utility.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,8 @@ public static void CreateDisplayByFieldType(this RenderTreeBuilder builder, IEdi
470470
/// <param name="changedType"></param>
471471
/// <param name="isSearch"></param>
472472
/// <param name="lookupService"></param>
473-
public static void CreateComponentByFieldType(this RenderTreeBuilder builder, ComponentBase component, IEditorItem item, object model, ItemChangedType changedType = ItemChangedType.Update, bool isSearch = false, ILookupService? lookupService = null)
473+
/// <param name="skipValidate"></param>
474+
public static void CreateComponentByFieldType(this RenderTreeBuilder builder, ComponentBase component, IEditorItem item, object model, ItemChangedType changedType = ItemChangedType.Update, bool isSearch = false, ILookupService? lookupService = null, bool? skipValidate = null)
474475
{
475476
var fieldType = item.PropertyType;
476477
var fieldName = item.GetFieldName();
@@ -488,7 +489,7 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co
488489
builder.AddAttribute(30, nameof(ValidateBase<string>.ValueChanged), fieldValueChanged);
489490
builder.AddAttribute(40, nameof(ValidateBase<string>.ValueExpression), valueExpression);
490491
builder.AddAttribute(41, nameof(ValidateBase<string>.ShowRequired), GetRequired(item, changedType));
491-
builder.AddAttribute(41, nameof(ValidateBase<string>.RequiredErrorMessage), item.RequiredErrorMessage);
492+
builder.AddAttribute(42, nameof(ValidateBase<string>.RequiredErrorMessage), item.RequiredErrorMessage);
492493

493494
if (!item.CanWrite(model.GetType(), changedType, isSearch))
494495
{
@@ -504,6 +505,11 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co
504505
{
505506
builder.AddAttribute(70, nameof(ValidateBase<string>.ShowLabelTooltip), item.ShowLabelTooltip);
506507
}
508+
509+
if (skipValidate is true)
510+
{
511+
builder.AddAttribute(71, nameof(ValidateBase<string>.SkipValidate), true);
512+
}
507513
}
508514

509515
if (componentType == typeof(NullSwitch) && TryGetProperty(model.GetType(), fieldName, out var propertyInfo))
@@ -547,7 +553,7 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co
547553
}
548554

549555
// 设置 SkipValidate 参数
550-
if (IsValidComponent(componentType))
556+
if (skipValidate is not true && IsValidComponent(componentType))
551557
{
552558
builder.AddAttribute(160, nameof(IEditorItem.SkipValidate), isSearch || item.SkipValidate);
553559
}

test/UnitTest/Utils/UtilityTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void CreateDisplayByFieldType_Formatter()
254254
public void CreateComponentByFieldType_Ok()
255255
{
256256
var editor = new MockNullDisplayNameColumn("Name", typeof(string)) { Readonly = true };
257-
var fragment = new RenderFragment(builder => builder.CreateComponentByFieldType(new BootstrapBlazorRoot(), editor, new Foo() { Name = "Test-Component" }));
257+
var fragment = new RenderFragment(builder => builder.CreateComponentByFieldType(new BootstrapBlazorRoot(), editor, new Foo() { Name = "Test-Component" }, skipValidate: true));
258258
var cut = Context.Render(builder => builder.AddContent(0, fragment));
259259
Assert.Contains("value=\"Test-Component\"", cut.Markup);
260260
}

0 commit comments

Comments
 (0)