Register page
This commit is contained in:
		| @@ -0,0 +1,46 @@ | ||||
| <h3>CustomValidation</h3> | ||||
|  | ||||
| @code { | ||||
|     private ValidationMessageStore? messageStore; | ||||
|  | ||||
|     [CascadingParameter] | ||||
|     private EditContext? CurrentEditContext { get; set; } | ||||
|  | ||||
|     protected override void OnInitialized() | ||||
|     { | ||||
|         if (CurrentEditContext is null) | ||||
|         { | ||||
|             throw new InvalidOperationException( | ||||
|                 $"{nameof(CustomValidation)} requires a cascading " + | ||||
|                 $"parameter of type {nameof(EditContext)}. " + | ||||
|                 $"For example, you can use {nameof(CustomValidation)} " + | ||||
|                 $"inside an {nameof(EditForm)}."); | ||||
|         } | ||||
|  | ||||
|         messageStore = new(CurrentEditContext); | ||||
|  | ||||
|         CurrentEditContext.OnValidationRequested += (_, _) => | ||||
|             messageStore?.Clear(); | ||||
|         CurrentEditContext.OnFieldChanged += (_, e) => | ||||
|             messageStore?.Clear(e.FieldIdentifier); | ||||
|     } | ||||
|  | ||||
|     public void DisplayErrors(Dictionary<string, List<string>> errors) | ||||
|     { | ||||
|         if (CurrentEditContext is not null) | ||||
|         { | ||||
|             foreach (var err in errors) | ||||
|             { | ||||
|                 messageStore?.Add(CurrentEditContext.Field(err.Key), err.Value); | ||||
|             } | ||||
|  | ||||
|             CurrentEditContext.NotifyValidationStateChanged(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public void ClearErrors() | ||||
|     { | ||||
|         messageStore?.Clear(); | ||||
|         CurrentEditContext?.NotifyValidationStateChanged(); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user