You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Connected.Components/Components/Table/TableRowValidator.cs

60 lines
1.1 KiB

2 years ago
namespace Connected.Components;
public class TableRowValidator : IForm
{
public bool IsValid
{
get
{
Validate();
return Errors.Length <= 0;
}
}
public string[] Errors
{
get => _errors.ToArray();
}
#nullable enable
public object? Model { get => throw new System.NotImplementedException(); set => throw new System.NotImplementedException(); }
#nullable disable
protected HashSet<string> _errors = new();
void IForm.FieldChanged(IFormComponent formControl, object newValue)
{
//implement in future for table
}
void IForm.Add(IFormComponent formControl)
{
_formControls.Add(formControl);
}
void IForm.Remove(IFormComponent formControl)
{
_formControls.Remove(formControl);
}
void IForm.Update(IFormComponent formControl)
{
//Validate(formControl);
}
protected HashSet<IFormComponent> _formControls = new();
public void Validate()
{
_errors.Clear();
foreach (var formControl in _formControls.ToArray())
{
formControl.Validate();
foreach (var err in formControl.ValidationErrors)
{
_errors.Add(err);
}
}
}
}