Skip to content

feat(BootstrapInput): BootstrapInput Bind non-nullable TValue int, float, double, decimal Setting Default Value to Zero When Null #3931

@mrtonyguo

Description

@mrtonyguo

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

复现步骤:

  1. 附件最小Demo,打开Home.razor页面, Demo里测试绑定的泛型数据为 不可为Null的decimal, 在BootstrapInput框里输入 数字 300,然后全选中数字,执行一次性删除,在下面div标签里能看到绑定的decimal值还是300;
    image
    image

Steps:

  1. Open the Home.razor page with the min demo in the attachment. The data bind-value for evaluation in the demo is a non-nullable decimal.
  2. Enter the number 300 in the BootstrapInput Components, then select all the numbers and perform a one-time deletion.
  3. You can see that the bound decimal value is still 300 in the div tag below;

Describe the solution you'd like

  1. 附件请查收Demo

  2. 经查阅源代码,是否可以在ValidateBase.cs绑定的泛型CurrentValueAsString里新增对于不可为Null的数字类型进行判断,如果为空值则等于对应类型的默认值,添加如下代码,经测试可行,烦请审阅:
    image

else if (typeof(TValue).IsValueType && Nullable.GetUnderlyingType(typeof(TValue)) == null && string.IsNullOrEmpty(value)) { // Non-nullable value type (e.g., int, double, etc.) PreviousParsingAttemptFailed = false; CurrentValue = default!; }
BootstrapBlazor.Net8.zip

Additional context

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions