Blazorise Validation API
Explore the Blazorise Validation API reference for parameters, events, methods, and related types.
For examples and usage guidance, see the Validation documentation.
API
Parameters
Validations
| Parameter | Description | Type | Default |
|---|---|---|---|
ChildContent |
Specifies the content to be rendered inside this Validations. |
RenderFragment | null |
EditContext |
Supplies the edit context explicitly. If using this parameter, do not also supply Model, since the model value will be taken from the EditContext.Model property. |
EditContext | null |
HandlerType |
Specifies the default handler type that will be used by the validation, unless it is overriden by HandlerType property. |
Type | null |
MissingFieldsErrorMessage |
Message that will be displayed if any of the validations does not have defined error message. |
string | |
Mode |
Specifies the validation mode for validations inside of this container. Possible values: |
ValidationMode | ValidationMode.Auto |
Model |
Specifies the top-level model object for the form. An edit context will be constructed for this model. If using this parameter, do not also supply a value for EditContext. |
object | null |
ValidateOnLoad |
If set to true, and Mode is set to Auto, validation will run automatically on page load. RemarksWhen validation is placed inside of modal dialog, the behavior is a little different. Modals are by definition always loaded and are always present in the DOM so no loading is ever happening again after the page that contains the modal is first initialized. Their visibility is controlled by display: none; To workaround this, the actual "first load" for modals can be done by re-initializing Model parameter. |
bool | true |
Validation
| Parameter | Description | Type | Default |
|---|---|---|---|
ChildContent |
Specifies the content to be rendered inside this Validation. |
RenderFragment | null |
HandlerType |
Forces the custom validation handler to be used while validating the values. |
Type | null |
Status |
Gets the last received validation status. Possible values: |
ValidationStatus | ValidationStatus.None |
UsePattern |
Forces validation to use regex pattern matching instead of default validator handler. |
bool | false |
ValidationNone
| Parameter | Description | Type | Default |
|---|---|---|---|
ChildContent |
Specifies the content to be rendered inside this ValidationNone. |
RenderFragment | null |
ValidationSuccess
| Parameter | Description | Type | Default |
|---|---|---|---|
ChildContent |
Specifies the content to be rendered inside this ValidationSuccess. |
RenderFragment | null |
Tooltip |
Shows the tooltip instead of label. |
bool | false |
ValidationWarning
| Parameter | Description | Type | Default |
|---|---|---|---|
ChildContent |
Specifies the content to be rendered inside this ValidationWarning. |
RenderFragment | null |
Multiline |
If true, shows the multiline warning messages. |
bool | false |
Tooltip |
If true, shows the tooltip instead of label. |
bool | false |
ValidationError
| Parameter | Description | Type | Default |
|---|---|---|---|
ChildContent |
Specifies the content to be rendered inside this ValidationError. |
RenderFragment | null |
Multiline |
If true, shows the multiline error messages. |
bool | false |
Tooltip |
If true, shows the tooltip instead of label. |
bool | false |
ValidationFeedback
| Parameter | Description | Type | Default |
|---|---|---|---|
ChildContent |
Specifies the content to be rendered inside this ValidationFeedback. |
RenderFragment | null |
Error |
Content rendered when the validation status is Error. |
RenderFragment | null |
Multiline |
If true, shows multiline validation messages. |
bool | false |
None |
Content rendered when the validation status is None. |
RenderFragment | null |
Success |
Content rendered when the validation status is Success. |
RenderFragment | null |
Tooltip |
If true, shows the validation message as a tooltip. |
bool | false |
Warning |
Content rendered when the validation status is Warning. |
RenderFragment | null |
Events
Validations
| Event | Description | Type |
|---|---|---|
FailedValidationsChanged |
Event is fired whenever the failed validation messages change. |
EventCallback<FailedValidationsEventArgs> |
StatusChanged |
Event is fired whenever there is a change in validation status. |
EventCallback<ValidationsStatusChangedEventArgs> |
ValidatedAll |
Event is fired only after all of the validation are successful. |
EventCallback |
Validation
| Event | Description | Type |
|---|---|---|
AsyncValidator |
Gets the asynchronous validator handler attached to this validation. |
Func<ValidatorEventArgs, CancellationToken, Task> |
MessageLocalizer |
Overrides the message that is going to be shown on the ValidationError or ValidationSuccess. |
Func<string, IEnumerable<string>, string> |
StatusChanged |
Occurs each time that validation status changed. |
EventCallback<ValidationStatus> |
Validator |
Gets the validator handler attached to this validation. |
Action<ValidatorEventArgs> |
Methods
Validations
| Method | Description | Return | Parameters |
|---|---|---|---|
ClearAll |
Clears all validation statuses. | Task | |
NotifyValidationInitialized |
Notifies the validation system that a new validation component has been initialized and adds it to the list of validations if not already present. | void | IValidation validation |
NotifyValidationRemoved |
Notifies the validation system that a validation component is being removed and removes it from the list of validations if present. | void | IValidation validation |
NotifyValidationStatusChanged |
Notifies the validation system that the status of a validation component has changed. This method handles the logic for updating the overall validation status based on the mode (Auto or Manual) and the current validation results.
RemarksIn Auto mode, this method triggers the aggregation of validation results and potentially raises a status changed event. It is designed to minimize the number of status changed events by aggregating validation results. Special consideration is needed to ensure that the status changed event is raised only once per validation cycle, even if multiple validations fail. | void | IValidation validation |
RetriggerValidation |
Retriggers validations for the specified model fields. | Task | Expression<Func<object>>[] expressions |
RetriggerValidation |
Retriggers validations that match the given FieldIdentifier instances. | Task | FieldIdentifier[] fieldIdentifiers |
ValidateAll |
Asynchronously runs the validation process for all validations and returns false if any is failed. | Task<bool> |
Validation
| Method | Description | Return | Parameters |
|---|---|---|---|
Clear |
Clears the validation status. | void | |
InitializeInputExpression |
Initializes or updates the input based on a specified expression. This is primarily used for data-annotation validation.
RemarksThis method is designed to work with models and edit contexts, allowing for dynamic validation based on expressions. It ensures that validation is only re-triggered if the component has been initialized and validation conditions are met. | Task | Expression<Func<T>> expression |
InitializeInputPattern |
Initializes or updates the input validation pattern. If the pattern string changes, a new regex pattern is created, and the input is re-validated if applicable.
RemarksThis method optimizes performance by avoiding re-instantiation of the regex pattern if it has not changed. It ensures that validation is only re-triggered if the component has been initialized and validation conditions are met. | Task | string patternString, T value |
InitializeInput |
Initializes the input component with the specified validation input. It performs an initial validation if the mode is set to auto validation and validation on load is enabled.
RemarksThis method sets the input component and, based on the configuration, may asynchronously validate the component's validation value. It also marks the component as initialized. | Task | IValidationInput inputComponent |
NotifyInputChanged |
Notifies that an input's value has changed and optionally re-validates the input.
RemarksIf the edit context is set and a field identifier has been established, this method notifies the edit context of the field change. It then conditionally triggers validation based on the component's mode. | Task | T newExpressionValue, bool overrideNewValue |
NotifyValidationStarted |
Notifies the validation that validation process has being activated. | void | |
NotifyValidationStatusChanged |
Notifies the validation with the new status and messages. | void | ValidationStatus status, IEnumerable<string> messages |
RetriggerValidation |
Runs the asynchronous validation process using the current input value. Can be used to manually retrigger validation. | Task<ValidationStatus> | |
ValidateAsync |
Runs the asynchronous validation process based on the last available value. | Task<ValidationStatus> | |
ValidateAsync |
Runs the asynchronous validation process. | Task<ValidationStatus> | object newValidationValue |
Validate |
Runs the validation process. | ValidationStatus | |
Validate |
Runs the validation process. | ValidationStatus | object newValidationValue |