Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 7 additions & 0 deletions src/BootstrapBlazor/Components/Select/Select.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ export function hide(id) {
}
}

export function resetValue(id, value) {
const input = document.getElementById(id);
if (input) {
input.value = value;
}
}

export function dispose(id) {
const select = Data.get(id)
Data.remove(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="dropdown-toggle" data-bs-toggle="@ToggleString" data-bs-placement="@PlacementString" data-bs-offset="@OffsetString" data-bs-custom-class="@CustomClassString">
@if (DisplayTemplate != null)
{
<div id="@InputId" class="@InputClassString" tabindex="0">
<div id="@InputId" class="@InputClassString">
@DisplayTemplate(SelectedRow)
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,11 @@

/// <summary>
/// 获得/设置 选项输入更新后转换为 Value 回调方法 默认 null
/// <para>返回值为 null 时放弃操作</para>
/// </summary>
/// <remarks>设置 <see cref="IsEditable"/> 后生效</remarks>
[Parameter]
public Func<string, Task<TValue>>? TextConvertToValueCallback { get; set; }
public Func<string, Task<TValue?>>? TextConvertToValueCallback { get; set; }

/// <summary>
/// 获得/设置 选项模板支持静态数据
Expand Down Expand Up @@ -486,17 +487,24 @@

if (item == null)
{
TValue val = default!;
TValue? val = default;
if (TextConvertToValueCallback != null)
{
val = await TextConvertToValueCallback(v);
}
item = new SelectedItem<TValue>(val, v);

var items = new List<SelectedItem<TValue>>() { item };
items.AddRange(Items);
Items = items;
CurrentValue = val;
if (val is not null)
{
item = new SelectedItem<TValue>(val, v);
var items = new List<SelectedItem<TValue>>() { item };
items.AddRange(Items);
Items = items;
CurrentValue = val;
}
else
{

Check warning on line 505 in src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs

View check run for this annotation

Codecov / codecov/patch

src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs#L505

Added line #L505 was not covered by tests
await InvokeVoidAsync("resetValue", InputId, SelectedRow?.Text);
}

Check warning on line 507 in src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs

View check run for this annotation

Codecov / codecov/patch

src/BootstrapBlazor/Components/SelectGeneric/SelectGeneric.razor.cs#L507

Added line #L507 was not covered by tests
}
else
{
Expand Down
Loading