Blazor form Validation should have IsValid() method #35260
Labels
area-blazor
Includes: Blazor, Razor Components
enhancement
This issue represents an ask for new feature or an enhancement to an existing one
feature-blazor-form-validation
This issue is related to forms validation in Blazor
Milestone
Currently a form can be validated with
editContext.Validate()
but that's not always the desired way to know if the form is valid. For example, according to docs [https://docs.microsoft.com/en-us/aspnet/core/blazor/forms-validation?view=aspnetcore-5.0#enable-the-submit-button-based-on-form-validation-1], enabling submit button upon field change has this side effect:The ValidationMessages errors appear even if the inputs are NOT marked modified (if they are required but untouched, which is correct during full validation)
The document suggest hiding ValidationSummary with a parameter but if the user is using ValidationMessages, then all inputs errors are triggered. MessageStore.Clear() does not clear these errors because it doesn't interact with fieldstate of editcontext.
If the user just wants to know if the form is valid at a given time (i.e. OnFieldChange) there should be a method returning a bool without actually triggering errors. EditContext has GetValidationMessages method but that's based on previous validation request.
If we can have an IsValid method or change MessageStore.Clear method to clear EditContext fieldstates then this can be archived.
The text was updated successfully, but these errors were encountered: