When values change in the Form Component. The Editform does not validate and it does not set the IsModified of the FieldState to true. Only on submit it will validate. I see when the values change, the class "Modified" is not added the input tag in HTML. So it looks like the EditContext is not setting the FieldState?
How can I achieve that?
Many thanks!
Code (Simplified):
Form Component
@typeparam TItem
<EditForm EditContext="_editContext" OnValidSubmit="OnValidSumit">
<DataAnnotationsValidator />
<ValidationSummary />
@ChildContent
</EditForm>
@code {
[Parameter] public TItem Model { get; set; }
[Parameter] public EventCallback OnValidSumit { get; set; }
[Parameter] public RenderFragment ChildContent { get; set; }
private EditContext _editContext;
protected override void OnParametersSet()
{
_editContext = new EditContext(Model);
}
}
PS When I use OnInitialized instead of OnParametersSet, I get the modified class. But then there is a problem with the DataAnnotationsValidator. It's like it's not seeing the value of the EditContext and wil always be valid or invalid on value change (after the frist submit).
protected override void OnInitialized()
{
_editContext = new EditContext(Model);
}
Parent Component
<Form Model="someModel" OnValidSumit="Save">
<InputNumber @bind-Value="Model.Number" />
<InputText @bind-Value="Model.Name" />
<button type="submit">Add</button>
</Form>
@code {
public class SomeModel
{
public int Id { get; set; }
public string Name { get; set; }
}
public SomeModel someModel = new SomeModel();
}