Blazor / MudBlazor Validation Inside Table

Viewed 31

I have a Blazor App using MudBlazor components. Im am trying to validate entry into a TextField contained in a table Td.

I embed the form inside the Td and it works, but it validates every row. I then try using the SelectedItemChanged event to capture the object for that row and put the Td inside an if statement that checks the context against the SelectedItem. The logic works but when clicking into a new cell the last cell un-renders, all values are still there in the background.

Anyone got validation working inside a MudBlazor Table know what's going on here?

@if (context.VariableName == currentVariableSelected.VariableName)
{
    <MudTd>
        <MudForm Model="@context" @ref="@localVariableForm" Validation="@(localVariableValidator.ValidateValue)" ValidationDelay="500">
            <MudTextField @bind-value="@context.VariableName" For="@(() => context.VariableName)"
                          Immediate="true" DisableUnderLine="true" Class="mt-n3" T="string"
                          TextChanged="@((string name) => OnLocalVariableNameChanged(name, context))">
            </MudTextField>
        </MudForm>
    </MudTd>
}
else
{
    <MudTd>
        <MudTextField @bind-value="@context.VariableName" For="@(() => context.VariableName)"
                      DisableUnderLine="true" Class="mt-n3" T="string">
        </MudTextField>
    </MudTd>
}

Same thing occurs if you move the Td to the outside of the if.

0 Answers
Related