I have a Blazor component called EditOffice. It looks as follows:
<EditForm Model="@Office" OnValidSubmit="@HandleValidSubmit">
<DataAnnotationsValidator />
<ValidationSummary />
<InputTextRow Label="Name" @bind-Value="@Office.Name" Placeholder="Enter name" />
<InputTextRow Label="ABN" @bind-Value="@Office.ABN" Placeholder="Enter ABN" />
...
<button type="submit" class="btn btn-primary edit-btn">Save office</button>
</EditForm>
I created child components called InputTextRow in an attempt to Tidy my code. They look as follows:
<div class="form-group row">
<label for="@Id" class="col-sm-3">@Label: </label>
<InputText id="@Id" @oninput="OnValueChanged" @bind-Value="@Value" class="form-control col-sm-8" placeholder="@Placeholder"></InputText>
<ValidationMessage class="offset-sm-3 col-sm-8" For="@(() => Value)" />
</div>
@code {
public string Id => Label.ToLower().Replace(" ", "");
[Parameter]
public string Label { get; set; }
[Parameter]
public string Value { get; set; }
[Parameter]
public string Placeholder { get; set; }
[Parameter] public EventCallback<string> ValueChanged { get; set; }
Task OnValueChanged(ChangeEventArgs e)
{
Value = e.Value.ToString();
return ValueChanged.InvokeAsync(Value);
}
}
The ValidationMessage doesn't work when in my child component. Any idea why?