When using blazor its important to create reusable custom components; that's one of the main points to use Blazor.
I've created a basic Input component that uses Bootstrap for its CSS as shown.
@inherits InputBase<string>
<InputText type="@Type"
class="form-control"
id="@_id"
placeholder="@Placeholder"
@bind-Value="CurrentValue"
disabled="@Disabled"
@attributes="AdditionalAttributes"/>
/* Additional properties below for placeholder, disabled, type, etc. they're just string properties */
I place this inside an EditForm like so...
<EditForm Model="MyModel"
OnValidSubmit="ViewModel.CreateAsync">
<DataAnnotationsValidator />
<PrimaryInput @bind-Value="MyModel.Name"
Placeholder="Name..."/>
</EditForm>
Problem is, this doesn't add the "invalid" class to the item. Both valid and modified appear, but once the input becomes invalid it does not change valid to invalid like it would with a none custom component. This is my model below to show I've added validation to the model.
public class MyModel
{
[StringLength(5)]
[Required]
public string Name { get; set; }
}
Below is the image of what is displayed:
This is the html that is generated by Blazor...
<input type="text" id="aa106d17-46d7-442c-be39-6c947f17186b" placeholder="Name..." aria-describedby="14b1189e-c3c5-4e1f-ae1d-330756147b44" class="form-control valid" aria-invalid="">
...as you can see, the class is still valid but the aria-invalid attribute has been applied. Below is the HTML for a none custom component input being validated...
<input class="modified invalid" aria-invalid="">
...on this one, invalid is applied. Something is preventing the class from switching to invalid on the custom component.
