Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.6.2-beta03</Version>
<Version>9.6.2-beta04</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Components/Table/Table.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -1382,7 +1382,7 @@ void SetDynamicEditTemplate()
parameters.Add(new(nameof(ValidateBase<string>.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);
};
}

Expand Down
12 changes: 9 additions & 3 deletions src/BootstrapBlazor/Utils/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ public static void CreateDisplayByFieldType(this RenderTreeBuilder builder, IEdi
/// <param name="changedType"></param>
/// <param name="isSearch"></param>
/// <param name="lookupService"></param>
public static void CreateComponentByFieldType(this RenderTreeBuilder builder, ComponentBase component, IEditorItem item, object model, ItemChangedType changedType = ItemChangedType.Update, bool isSearch = false, ILookupService? lookupService = null)
/// <param name="skipValidate"></param>
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();
Expand All @@ -488,7 +489,7 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co
builder.AddAttribute(30, nameof(ValidateBase<string>.ValueChanged), fieldValueChanged);
builder.AddAttribute(40, nameof(ValidateBase<string>.ValueExpression), valueExpression);
builder.AddAttribute(41, nameof(ValidateBase<string>.ShowRequired), GetRequired(item, changedType));
builder.AddAttribute(41, nameof(ValidateBase<string>.RequiredErrorMessage), item.RequiredErrorMessage);
builder.AddAttribute(42, nameof(ValidateBase<string>.RequiredErrorMessage), item.RequiredErrorMessage);

if (!item.CanWrite(model.GetType(), changedType, isSearch))
{
Expand All @@ -504,6 +505,11 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co
{
builder.AddAttribute(70, nameof(ValidateBase<string>.ShowLabelTooltip), item.ShowLabelTooltip);
}

Copy link

Copilot AI May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Document that a null value for skipValidate is treated as false to ensure API consumers understand the default behavior.

Suggested change
// If skipValidate is null, it is treated as false by default.

Copilot uses AI. Check for mistakes.
if (skipValidate is true)
{
builder.AddAttribute(71, nameof(ValidateBase<string>.SkipValidate), true);
}
}

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

// 设置 SkipValidate 参数
Copy link

Copilot AI May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding an inline comment clarifying the decision to skip adding the SkipValidate attribute when skipValidate is true, to assist future maintainers.

Suggested change
// 设置 SkipValidate 参数
// 设置 SkipValidate 参数
// Add the SkipValidate attribute only if skipValidate is false and the component type is valid.
// This ensures that validation is skipped only when explicitly allowed by the conditions.

Copilot uses AI. Check for mistakes.
if (IsValidComponent(componentType))
if (skipValidate is not true && IsValidComponent(componentType))
{
builder.AddAttribute(160, nameof(IEditorItem.SkipValidate), isSearch || item.SkipValidate);
}
Expand Down
2 changes: 1 addition & 1 deletion test/UnitTest/Utils/UtilityTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (testing): Enhance assertion to verify SkipValidate attribute presence.

Update the assertion to verify the rendered markup includes the SkipValidate attribute or that the component instance’s skipValidate parameter is true.

Suggested change
Assert.Contains("value=\"Test-Component\"", cut.Markup);
Assert.Contains("value=\"Test-Component\"", cut.Markup);
// Verify that SkipValidate attribute is rendered
Assert.Contains("skip-validate", cut.Markup);

}
Expand Down