Is there a way to either find out if a specific control (i.e. TextBox) is valid or not when using validators when clicking a button in codebehind?
In my scenario, I have a email textbox with an Add button so that the user can add multiple emails to a listbox. I am using the email validator which validates the format but if I enter an invalid format and click the Add button, it ends up adding it to the listbox anyway. I guess another way this could be handled would be to only enable the Add button if the email entered is valid. I could use either solution but not sure how to go about it. Here are my controls:
<RadzenRow JustifyContent="JustifyContent.Center" AlignItems="AlignItems.Center" Gap="1em" class="rz-p-1">
<RadzenColumn Size="5" class="rz-text-align-right">
<RadzenText Text="Email:" />
</RadzenColumn>
<RadzenColumn Size="7" class="rz-text-align-left">
<RadzenTextBox Name="Email" @bind-Value=@email MaxLength="50" Style="width:300px;" Disabled=@disabled></RadzenTextBox>
<RadzenButton Shade="Shade.Dark" Click=@(args => AddEmail()) Text="Add"
ButtonStyle="ButtonStyle.Info" Disabled=@disabled />
<RadzenEmailValidator Component="Email" Text="Provide a valid email address" Popup=false />
</RadzenColumn>
</RadzenRow>
<RadzenRow JustifyContent="JustifyContent.Center" AlignItems="AlignItems.Start" Gap="1em" class="rz-p-1">
<RadzenColumn Size="5" class="rz-text-align-right">
</RadzenColumn>
<RadzenColumn Size="7" class="rz-text-align-left">
<RadzenListBox @bind-Value=@emailToRemove Data="@emails" Name="Emails"
Style="width: 100%; max-width: 291px; height: 113px" Disabled=@disabled />
<RadzenButton Shade="Shade.Dark" Click=@(args => RemoveEmail()) Text="Remove"
ButtonStyle="ButtonStyle.Danger" Disabled=@disabled />
<RadzenCustomValidator Component="Emails" Validator="@(() => ValidateListCount(emails))" Text="At least one email is requred." Popup=false />
</RadzenColumn>
</RadzenRow>