Select field


Manual Options

TODO: text...

Option: null
Blazor
<BspSelectField Label="Options" @bind-Value="_option">
    <option value="">Select an option...</option>
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
</BspSelectField>
<div>Option: @(_option is null ? "null" : _option.ToString())</div>
@code {
    private int? _option = null;
}

From a collection of Tuple(T value, string text)

TODO: text...

Option: null
Blazor
<BspSelectField Label="Options" 
                Options="@([(1, "Option 1"), (2, "Option 2")])"
                @bind-Value="_option"/>
<div>Option: @(_option is null ? "null" : _option.ToString())</div>
@code {
    private int? _option = null;
}

Loading options from task

TODO: text...

Option: null
Blazor
<BspSelectField Label="Load Options"
                LoadOptions="LoadOptionsAsync"
                @bind-Value="_option" />
<div>Option: @(_option is null ? "null" : _option.ToString())</div>
@code {
    private int? _option = null;

    private async Task<IEnumerable<(int? value, string name)>> LoadOptionsAsync()
    {
        if (RendererInfo.IsInteractive)
        {
            await Task.Delay(5000);
        }
        return [(1, "Option 1"), (2, "Option 2")];
    }
}

Configuration options

For the Options and LoadOptions it is possible to define default loading and empty option texts

builder.Services.AddBsBlazorPlusOptions(options =>
{
    options.SelectField.DefaultEmptyOptionText = "Select an option...";
    options.SelectField.DefaultLoadingText = "Loading...";
});