Add the ability to clear validation errors
This commit is contained in:
@@ -14,8 +14,10 @@ public interface IValidation :
|
|||||||
ValidationRule[] rules,
|
ValidationRule[] rules,
|
||||||
ValidationTrigger trigger = ValidationTrigger.Deferred);
|
ValidationTrigger trigger = ValidationTrigger.Deferred);
|
||||||
|
|
||||||
|
void Clear();
|
||||||
|
|
||||||
Task<bool> Validate<TProperty>(Expression<Func<TProperty>> property,
|
Task<bool> Validate<TProperty>(Expression<Func<TProperty>> property,
|
||||||
ValidationRule[] rules);
|
ValidationRule[] rules);
|
||||||
|
|
||||||
Task<bool> Validate();
|
Task<bool> Validate();
|
||||||
|
|
||||||
|
|||||||
@@ -31,8 +31,14 @@ public class Validation(IValidatorCollection validators) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Clear()
|
||||||
|
{
|
||||||
|
errors.Clear();
|
||||||
|
OnPropertyChanged(nameof(Errors), null, null);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void OnPropertyChanged(string propertyName,
|
public virtual void OnPropertyChanged(string propertyName,
|
||||||
object? before, object? after)
|
object? before, object? after)
|
||||||
{
|
{
|
||||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
}
|
}
|
||||||
@@ -83,6 +89,7 @@ public class Validation(IValidatorCollection validators) :
|
|||||||
public async Task<bool> Validate()
|
public async Task<bool> Validate()
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
foreach (Validator? validator in Validators)
|
foreach (Validator? validator in Validators)
|
||||||
{
|
{
|
||||||
if (validator.PropertyName is string name)
|
if (validator.PropertyName is string name)
|
||||||
@@ -109,13 +116,6 @@ public class Validation(IValidatorCollection validators) :
|
|||||||
OnPropertyChanged(nameof(Errors), null, null);
|
OnPropertyChanged(nameof(Errors), null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Clear()
|
|
||||||
{
|
|
||||||
errors.Clear();
|
|
||||||
OnPropertyChanged(nameof(Errors), null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private string GetPropertyName<T>(Expression<Func<T>> expression)
|
private string GetPropertyName<T>(Expression<Func<T>> expression)
|
||||||
{
|
{
|
||||||
return expression.Body switch
|
return expression.Body switch
|
||||||
|
|||||||
Reference in New Issue
Block a user