isValidForm method

bool isValidForm()

Validates all form fields and returns true if the form is valid.

Implementation

bool isValidForm() {
  if (!submitted) {
    submitted = true; // Mark form as submitted
  }
  errors.clear(); // Clear previous validation errors

  for (var field in allFields) {
    debugPrint("field: ${field.name}");
    validateField(field);
  }

  notifyListeners();

  // If formValidation is "optional" and no fields are touched, consider form valid
  if (formValidation == "optional" && !touched.values.any((touch) => touch)) {
    return true;
  }

  // Otherwise, form is valid if there are no errors
  return !errors.values.any((error) => error != null);
}