VeryGoodOpenSource / VeryGoodOpenSource/formz
Form-Level Validation Rule
Nobody has claimed this yet.
- Dominant language
- Dart
- Stars
- 487
- Forks
- 42
- Avg merge
- 4d 9h
- Merged PRs (30d)
- 2
Description
Is your feature request related to a problem? Please describe.
Currently, the formz package excels at validating individual form fields and separating the validation logic. However, it lacks the ability to define a validation rule that applies to the entire form.
For instance, consider a use case where the user can look up a an employee by any 3 fields: phone number, first name, and last name. While formz allows validation for individual fields (e.g., ensuring phone number has 10 digits and names have at least two characters), there's no way to enforce that at least one field must be filled before submitting the search.
Describe the solution you'd like
One possible solution would involve introducing a mechanism to define form-level validation rules that can orchestrate the execution of individual field validators. In the example above, the form level validator would perform validation that least one of the three fields (phone number, first name, or last name) has a value before allowing form submission then to orchestrate the execution of individual field validators.
\\Something like
\\Form - Level validator
overide
ValidationError? validator(String value) {
if (isAllSearchParametersEmpty(firstName: firstName, lastName: lastName, phone: phone)) {
return AtLeastOneFieldNeededError();
}
//This idea
// Directly call field validators here
final phoneError = phone.validator();
final firstNameError = firstName.validator();
final lastNameError = lastName.validator();
// Combine errors for a holistic form-level validation result
return ... (logic to aggregate errors and return a representative error)
}
tiny code
/// ValidationError is an abstract class that is used to implement the builder pattern to create a validation error(s).
abstract class ValidationError {
final String message;
ValidationError(this.message);
}
I am happy create a pull request and discuss peoples thoughts on the best way to implement this
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading formz's existing individual field validators and the proposed form-level validator entry point. Determine how a rule requiring at least one of phone number, first name, or last name could coexist with individual validation and aggregate errors. Done means the package supports a documented form-level rule without leaving the validation result or submission behavior ambiguous.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100