Untitled

mail@pastecode.io avatar
unknown
razor
11 days ago
1.7 kB
4
Indexable
Never
    <!-- Category Selection -->
    <MudSelectExtended Class="mb-4" T="int?" Label="Select Product Category" Variant="Variant.Outlined" ToStringFunc="GetCategoryString"
                       Immediate="true" @bind-Value="Model.CategoryId" Error="@_productDetailsValidationErrors.ContainsKey(nameof(Model.CategoryId))"
                       @onfocus="ShowSearchBox" OnClose="HideSearchBox">

        @if (_categorySearchVisible)
        {
            <MudTextField T="string" Variant="Variant.Outlined" Immediate="true"
                          AdornmentIcon="@Icons.Material.Filled.Search" AdornmentColor="Color.Primary"
                          Placeholder="Search for a category"/>
        }
        @foreach (var category in Categories)
        {
            <MudSelectItemGroupExtended Class="mud-select-group" T="int?" Text="@category.Name" Nested="true" InitiallyExpanded="@(Categories.IndexOf(category) == 0)">
                @foreach (var subcategory in category.Subcategories)
                {
                    <MudSelectItemExtended Value="@(new int?(subcategory.CategoryId))">
                        @subcategory.Name
                    </MudSelectItemExtended>
                }
            </MudSelectItemGroupExtended>
        }
    </MudSelectExtended>
    
    private bool _categorySearchVisible;


private async Task ShowSearchBox()
    {
        _categorySearchVisible = true;
        await InvokeAsync(StateHasChanged);
    }

    private async Task HideSearchBox()
    {
        _categorySearchVisible = false;
        await InvokeAsync(StateHasChanged);
        await ValidateProductDetailsField(nameof(Model.CategoryId));
    }
Leave a Comment