validate method
validate form manually
if names
is not empty , will only validate these fields
if clearError
is true, will clear error first before validate
if validateByOrder
is true, will validate field by order , only one field will be validated at once
Implementation
Future<FormeValidateSnapshot> validate({
bool quietly = false,
Set<String> names = const {},
bool clearError = false,
bool validateByOrder = false,
}) async {
final List<FormeFieldState> states = (_states
.where((element) =>
element._hasAnyValidator &&
element.enabled &&
element.name != null &&
(names.isEmpty || names.contains(element.name)))
.toList()
..sort((a, b) => a.order!.compareTo(b.order!)))
.toList();
if (states.isEmpty) {
return FormeValidateSnapshot([]);
}
if (clearError) {
for (final FormeFieldState element in states) {
element.errorText = null;
}
}
if (validateByOrder) {
return _validateByOrderManually(states, quietly);
}
final List<FormeFieldValidateSnapshot> value = await Future.wait(
states.map((state) => state.validate(quietly: quietly)),
eagerError: true);
return FormeValidateSnapshot(value);
}