Skip to content

Commit d1898d0

Browse files
committed
Add more
1 parent 7b556b8 commit d1898d0

File tree

4 files changed

+23
-1
lines changed

4 files changed

+23
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* Add notMatch
1313
* Add range
1414
* Add date range
15+
* Add must be true
16+
* Add must be false
1517

1618
## 10.0.2
1719
* Reland generated l10n files

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ Available built-in validators include:
7575
- `FormBuilderValidators.lowercase()` - requires the field's value to be lowercase.
7676
- `FormBuilderValidators.fileExtension()` - requires the field's value to a valid file extension.
7777
- `FormBuilderValidators.fileSize()` - requires the field's to be less than the max size.
78+
- `FormBuilderValidators.mustBeTrue()` - requires the field's to be true.
79+
- `FormBuilderValidators.mustBeFalse()` - requires the field's to be false.
7880

7981
### Supported languages
8082

lib/l10n/intl_en.arb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@
2727
"lowercaseErrorText": "Value must be lowercase.",
2828
"fileExtensionErrorText": "File extension must be {extensions}",
2929
"fileSizeErrorText": "File size must be less than {maxSize} while it is {fileSize}",
30-
"dateRangeErrorText": "Date must be in range {min} - {max}"
30+
"dateRangeErrorText": "Date must be in range {min} - {max}",
31+
"mustBeTrueErrorText": "This field must be true.",
32+
"mustBeFalseErrorText": "This field must be false."
3133
}

lib/src/form_builder_validators.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,4 +496,20 @@ class FormBuilderValidators {
496496
],
497497
);
498498
}
499+
500+
/// [FormFieldValidator] that requires the field's value to be a bool and true.
501+
static FormFieldValidator<bool> mustBeTrue({
502+
String? errorText,
503+
}) =>
504+
(valueCandidate) => valueCandidate != true
505+
? errorText ?? FormBuilderLocalizations.current.mustBeTrueErrorText
506+
: null;
507+
508+
/// [FormFieldValidator] that requires the field's value to be a bool and false.
509+
static FormFieldValidator<bool> mustBeFalse({
510+
String? errorText,
511+
}) =>
512+
(valueCandidate) => valueCandidate != false
513+
? errorText ?? FormBuilderLocalizations.current.mustBeFalseErrorText
514+
: null;
499515
}

0 commit comments

Comments
 (0)