I am having a problem with validation of a editform in blazor.
My form is as follows.
<EditForm Model="@FormModel" OnValidSubmit="@HandleValidSubmit" OnInvalidSubmit="@HandleInValidSubmit">
<DataAnnotationsValidator />
<div>
<InputText class="form-control" id="firstName" type="text" placeholder="First Name" @bind-Value="@FormModel.FirstName" />
<label for="firstName">First Name</label>
<ValidationMessage For="@(() => FormModel.FirstName)" />
</div>
</EditForm>
If i submit the form from one that started out empty, the validation works fine.
In my .cs file i have…
FormModel = new FormUIModel();
The FormUIModel has a required parameter
[Required(ErrorMessage = "First Name Required")]
public string? FirstName { get; set; }
this works fine. But if I try and do it as an update, it does not Validate. It goes directly to the OnValidSubmit.
the only difference is that after I new up the FormModel, I then populate it as so..
FormModel = new FormUIModel();
FormModel = await _service.GetFormData(rowId)
Even if I delete the data in the firstname field, it will not show the ‘Required” message and never goes to the HandleInvalidSubmit.
Help is appreciated