Contact Form Validator
Component Detail
Description
Client-side validation utilities for the edit contact form, enforcing required field rules, format constraints (e.g., phone number, email), and organization-specific rules such as chapter affiliation limits.
contact-form-validator
Summaries
The Contact Form Validator ensures that member data entered by coordinators meets quality and accuracy standards before it ever reaches the database. By catching formatting errors, missing required fields, and organization-specific constraint violations — such as the NHF rule limiting chapter affiliations to five — directly on the device, coordinators receive immediate, actionable feedback rather than submitting bad data and discovering problems later. This reduces data cleanup burden on administrators, improves data quality across the organization, and gives coordinators confidence that what they enter is correct. As a shared component reused across contact editing flows, it also guarantees consistent rule enforcement regardless of which screen a coordinator uses.
Contact Form Validator is a low-complexity, shared utility with no upstream dependencies, making it an excellent candidate for early delivery — it can be completed and integrated into the edit contact form before more complex components are ready. The organization-specific rule (chapter affiliation limit of 5 for NHF) must be confirmed with the product owner before implementation, as hard-coded business rules that change after delivery require code updates rather than configuration changes. Since it is shared, define its public interface contract early so all consuming screens can rely on a stable API. Testing should include boundary cases for the chapter affiliation limit, international phone number formats, and email edge cases to avoid regressions when real coordinator data surfaces unexpected formats.
Contact Form Validator is a pure utility class (no I/O, no side effects) providing five validation methods. validateContactForm accepts a ContactEditPayload and returns a ValidationResult aggregating all field errors; individual validators (validateEmail, validatePhoneNumber, validateChapterAffiliationCount, validateRequiredFields) return nullable String error messages following Flutter's FormField validator convention, making them directly composable with AppTextField's errorText property. The chapter affiliation limit of 5 is an NHF-specific business rule — consider making it a named constant or injectable configuration value rather than a magic number to simplify future rule changes. Because this is a shared component, all validators must be pure functions with no dependency on widget state, BLoC, or platform channels, ensuring they can be unit-tested exhaustively without a Flutter test environment.
Responsibilities
- Validate required fields are non-empty before submission
- Enforce format rules for email, phone, and other typed fields
- Validate chapter affiliation count does not exceed 5 (NHF rule)
- Return field-level error messages for display in AppTextField
Interfaces
validateContactForm(ContactEditPayload payload) -> ValidationResult
validateEmail(String email) -> String?
validatePhoneNumber(String phone) -> String?
validateChapterAffiliationCount(List<String> chapterIds) -> String?
validateRequiredFields(Map<String, String> fields) -> Map<String, String>
Relationships
Dependents (2)
Components that depend on this component
Related Data Entities (2)
Data entities managed by this component