diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 6fb59027408..0eb1cc90f15 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 9.6.2-beta03 + 9.6.2-beta04 diff --git a/src/BootstrapBlazor/Components/Table/Table.razor.cs b/src/BootstrapBlazor/Components/Table/Table.razor.cs index 48e88a059e3..468b2d7830d 100644 --- a/src/BootstrapBlazor/Components/Table/Table.razor.cs +++ b/src/BootstrapBlazor/Components/Table/Table.razor.cs @@ -1340,7 +1340,7 @@ RenderFragment RenderTemplate() => col.Template == null : col.Template(item); RenderFragment RenderEditTemplate() => col.EditTemplate == null - ? new RenderFragment(builder => builder.CreateComponentByFieldType(this, col, item, changedType, false, col.GetLookupService(InjectLookupService))) + ? new RenderFragment(builder => builder.CreateComponentByFieldType(this, col, item, changedType, isSearch: false, col.GetLookupService(InjectLookupService), skipValidate: true)) : col.EditTemplate(item); } @@ -1382,7 +1382,7 @@ void SetDynamicEditTemplate() parameters.Add(new(nameof(ValidateBase.OnValueChanged), onValueChanged.Invoke(d, col, (model, column, val) => DynamicContext.OnValueChanged(model, column, val)))); col.ComponentParameters = parameters; } - builder.CreateComponentByFieldType(this, col, row, changedType, false, col.GetLookupService(InjectLookupService)); + builder.CreateComponentByFieldType(this, col, row, changedType, false, col.GetLookupService(InjectLookupService), skipValidate: true); }; } diff --git a/src/BootstrapBlazor/Utils/Utility.cs b/src/BootstrapBlazor/Utils/Utility.cs index 31dc5089feb..3cfdea287a8 100644 --- a/src/BootstrapBlazor/Utils/Utility.cs +++ b/src/BootstrapBlazor/Utils/Utility.cs @@ -470,7 +470,8 @@ public static void CreateDisplayByFieldType(this RenderTreeBuilder builder, IEdi /// /// /// - public static void CreateComponentByFieldType(this RenderTreeBuilder builder, ComponentBase component, IEditorItem item, object model, ItemChangedType changedType = ItemChangedType.Update, bool isSearch = false, ILookupService? lookupService = null) + /// + 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) { var fieldType = item.PropertyType; var fieldName = item.GetFieldName(); @@ -488,7 +489,7 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co builder.AddAttribute(30, nameof(ValidateBase.ValueChanged), fieldValueChanged); builder.AddAttribute(40, nameof(ValidateBase.ValueExpression), valueExpression); builder.AddAttribute(41, nameof(ValidateBase.ShowRequired), GetRequired(item, changedType)); - builder.AddAttribute(41, nameof(ValidateBase.RequiredErrorMessage), item.RequiredErrorMessage); + builder.AddAttribute(42, nameof(ValidateBase.RequiredErrorMessage), item.RequiredErrorMessage); if (!item.CanWrite(model.GetType(), changedType, isSearch)) { @@ -504,6 +505,11 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co { builder.AddAttribute(70, nameof(ValidateBase.ShowLabelTooltip), item.ShowLabelTooltip); } + + if (skipValidate is true) + { + builder.AddAttribute(71, nameof(ValidateBase.SkipValidate), true); + } } if (componentType == typeof(NullSwitch) && TryGetProperty(model.GetType(), fieldName, out var propertyInfo)) @@ -547,7 +553,7 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co } // 设置 SkipValidate 参数 - if (IsValidComponent(componentType)) + if (skipValidate is not true && IsValidComponent(componentType)) { builder.AddAttribute(160, nameof(IEditorItem.SkipValidate), isSearch || item.SkipValidate); } diff --git a/test/UnitTest/Utils/UtilityTest.cs b/test/UnitTest/Utils/UtilityTest.cs index dd9a83a7ef9..ce578e3cc9a 100644 --- a/test/UnitTest/Utils/UtilityTest.cs +++ b/test/UnitTest/Utils/UtilityTest.cs @@ -254,7 +254,7 @@ public void CreateDisplayByFieldType_Formatter() public void CreateComponentByFieldType_Ok() { var editor = new MockNullDisplayNameColumn("Name", typeof(string)) { Readonly = true }; - var fragment = new RenderFragment(builder => builder.CreateComponentByFieldType(new BootstrapBlazorRoot(), editor, new Foo() { Name = "Test-Component" })); + var fragment = new RenderFragment(builder => builder.CreateComponentByFieldType(new BootstrapBlazorRoot(), editor, new Foo() { Name = "Test-Component" }, skipValidate: true)); var cut = Context.Render(builder => builder.AddContent(0, fragment)); Assert.Contains("value=\"Test-Component\"", cut.Markup); }