Skip to content

Commit

Permalink
Corrected minLength and maxLength validators. (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
awhitford authored May 15, 2020
1 parent 58d7545 commit 929f63d
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/src/form_builder_validators.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@ class FormBuilderValidators {
String errorText,
}) {
return (valueCandidate) {
if (allowEmpty && (valueCandidate == null || valueCandidate?.length == 0))
return errorText ??
"Value must have a length greater than or equal to $minLength";
if (valueCandidate != null && valueCandidate.length < minLength) {
final valueLength = valueCandidate?.length ?? 0;
if (valueLength < minLength && (!allowEmpty || valueLength > 0)) {
return errorText ??
"Value must have a length greater than or equal to $minLength";
}
Expand All @@ -92,13 +90,8 @@ class FormBuilderValidators {
static FormFieldValidator maxLength(
num maxLength, {
String errorText,
bool allowEmpty = false,
}) {
return (valueCandidate) {
if (allowEmpty && (valueCandidate == null || valueCandidate?.length == 0))
return errorText ??
"Value must have a length greater than or equal to $minLength";

if (valueCandidate != null && valueCandidate.length > maxLength) {
return errorText ??
"Value must have a length less than or equal to $maxLength";
Expand Down

0 comments on commit 929f63d

Please sign in to comment.