Skip to content

Commit d76957d

Browse files
committed
Add allow empty in equalLength
1 parent 6eae9fe commit d76957d

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/src/form_builder_validators.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class FormBuilderValidators {
150150
/// equal to the provided length. Works with String, iterable and int types
151151
static FormFieldValidator<T> equalLength<T>(
152152
int length, {
153+
bool allowEmpty = false,
153154
String? errorText,
154155
}) {
155156
assert(length > 0);
@@ -164,7 +165,7 @@ class FormBuilderValidators {
164165
if (valueCandidate is String) valueLength = valueCandidate.length;
165166
if (valueCandidate is Iterable) valueLength = valueCandidate.length;
166167

167-
return valueLength != length
168+
return valueLength != length && (!allowEmpty || valueLength > 0)
168169
? errorText ??
169170
FormBuilderLocalizations.current.equalLengthErrorText(length)
170171
: null;

0 commit comments

Comments
 (0)