Skip to content

Commit ef2ff20

Browse files
implement notInList validators and add more migration guide items.
1 parent 51e1d84 commit ef2ff20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+282
-5
lines changed

README-updated.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ TextFormField(
156156
Validators that check a generic type user input.
157157

158158
- `Validators.inList(values)`: Checks if the field contains a value that is in the list `values`.
159+
- TODO [ ] `Validators.notInList(values)`: Checks if the field DOES NOT contain a value that is in the list `values`.
159160
- `Validators.isTrue()`: Checks if the field contains a boolean or a parsable `String` of the `true` value.
160161
- `Validators.isFalse()`: Checks if the field contains a boolean or a parsable `String` of the `false` value.
161162

doc/migration.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,56 @@ Validators.iban(ibanMsg: (_)=>'invalid iban');
673673

674674
### Identity validators
675675

676-
- `FormBuilderValidators.city()` - requires the field's value to be a valid city name.
677-
- `FormBuilderValidators.country()` - requires the field's value to be a valid country name.
676+
- `FormBuilderValidators.city()`: there is no equivalent to [this validator](https://github.com/flutter-form-builder-ecosystem/form_builder_validators/blob/17e982bb849dc68365f8fbc93d5a2323ee891c89/lib/src/identity/city_validator.dart#L53). Something close would be:
677+
```dart
678+
/// Old API:
679+
FormBuilderValidators.city(
680+
regex: RegExp(r'^[A-Z][a-zA-Z\s]+$'),
681+
citiesWhitelist: ['CityA', 'CityB', 'CityC'],
682+
citiesBlacklist: ['CityD', 'CityE'],
683+
errorText: 'invalid city',
684+
);
685+
686+
/// New API (expects input as String):
687+
Validators.and([
688+
Validators.match(
689+
RegExp(r'^[A-Z][a-zA-Z\s]+$'),
690+
matchMsg: (_)=>'invalid city'
691+
),
692+
Validators.inList(
693+
['CityA', 'CityB', 'CityC'],
694+
inListMsg: (_, __) => 'invalid city',
695+
),
696+
Validators.notInList(
697+
['CityD', 'CityE'],
698+
notInListMsg: (_, __) => 'invalid city',
699+
),
700+
]);
701+
```
702+
703+
- `FormBuilderValidators.country()`: there is no equivalent to [this validator](https://github.com/flutter-form-builder-ecosystem/form_builder_validators/blob/17e982bb849dc68365f8fbc93d5a2323ee891c89/lib/src/identity/country_validator.dart#L42). Something close would be:
704+
```dart
705+
/// Old API:
706+
FormBuilderValidators.country(
707+
countryWhitelist: ['CountryA', 'CountryB', 'CountryC'],
708+
countryBlacklist: ['CountryD', 'CountryE'],
709+
errorText: 'invalid country',
710+
);
711+
712+
/// New API (expects input as String):
713+
Validators.and([
714+
Validators.inList(
715+
['CountryA', 'CountryB', 'CountryC'],
716+
inListMsg: (_, __) => 'invalid country',
717+
),
718+
Validators.notInList(
719+
['CountryD', 'CountryE'],
720+
notInListMsg: (_, __) => 'invalid country',
721+
),
722+
]);
723+
```
724+
725+
TODO continue from here...
678726
- `FormBuilderValidators.firstName()` - requires the field's value to be a valid first name.
679727
- `FormBuilderValidators.lastName()` - requires the field's value to be a valid last name.
680728
- `FormBuilderValidators.passportNumber()` - requires the field's value to be a valid passport number.

example/lib/generic_examples.dart

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:form_builder_validators/form_builder_validators.dart'
3-
show Validators, Validator;
3+
show Validator, Validators;
44

55
/// alias for Validators class.
66
typedef V = Validators;
@@ -248,6 +248,31 @@ class GenericExamplesPage extends StatelessWidget {
248248
textInputAction: TextInputAction.done,
249249
autovalidateMode: AutovalidateMode.always,
250250
),
251+
TextFormField(
252+
decoration: const InputDecoration(
253+
labelText: 'City',
254+
prefixIcon: Icon(Icons.location_city),
255+
),
256+
validator: V.required(
257+
V.and(<Validator<String>>[
258+
V.match(
259+
RegExp(r'^[A-Z][a-zA-Z\s]+$'),
260+
matchMsg: (_) => 'invalid city',
261+
),
262+
V.inList(
263+
<String>['CityA', 'CityB', 'CityC'],
264+
inListMsg: (_, __) => 'invalid city',
265+
),
266+
V.notInList(
267+
<String>['CityD', 'CityE'],
268+
notInListMsg: (_, __) => 'invalid city',
269+
),
270+
]),
271+
'invalid city',
272+
),
273+
textInputAction: TextInputAction.done,
274+
autovalidateMode: AutovalidateMode.always,
275+
),
251276
],
252277
),
253278
),

lib/l10n/intl_ar.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"startsWithErrorText": "القيمة يجب أن تبدأ بـ {value}.",
6363
"endsWithErrorText": "القيمة يجب أن تنتهي بـ {value}.",
6464
"containsErrorText": "القيمة يجب أن تحتوي على {value}.",
65+
"doesNotContainElementErrorText": "القيمة قد لا تكون في القائمة.",
6566
"betweenErrorText": "القيمة يجب أن تكون بين {min} و {max}.",
6667
"containsElementErrorText": "القيمة يجب أن تكون ضمن القائمة المسموح بها.",
6768
"ibanErrorText": "هذا الحقل يتطلب IBAN صالح.",

lib/l10n/intl_bg.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"containsErrorText": "Стойността трябва да съдържа {value}.",
6565
"betweenErrorText": "Стойността трябва да е между {min} и {max}.",
6666
"containsElementErrorText": "Стойността трябва да е в списъка с допустими стойности.",
67+
"doesNotContainElementErrorText": "Стойността не може да бъде в списъка.",
6768
"ibanErrorText": "Това поле изисква валиден IBAN.",
6869
"uniqueErrorText": "Това поле изисква уникална стойност.",
6970
"bicErrorText": "Това поле изисква валиден BIC код.",

lib/l10n/intl_bn.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"containsErrorText": "মানটি {value} ধারণ করতে হবে।",
6565
"betweenErrorText": "মানটি {min} এবং {max} এর মধ্যে হতে হবে।",
6666
"containsElementErrorText": "মানটি অনুমোদিত তালিকার মধ্যে থাকতে হবে।",
67+
"doesNotContainElementErrorText": "মান তালিকায় থাকতে পারবে না।",
6768
"ibanErrorText": "একটি বৈধ IBAN প্রয়োজন।",
6869
"uniqueErrorText": "মানটি অবশ্যই অনন্য মানগুলির মধ্যে অদ্বিতীয় হতে হবে।",
6970
"bicErrorText": "একটি বৈধ BIC প্রয়োজন।",

lib/l10n/intl_bs.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"containsErrorText": "Vrijednost mora sadržavati {value}.",
6565
"betweenErrorText": "Vrijednost mora biti između {min} i {max}.",
6666
"containsElementErrorText": "Vrijednost mora biti na listi dopuštenih vrijednosti.",
67+
"doesNotContainElementErrorText": "Vrijednost ne smije biti na listi.",
6768
"ibanErrorText": "Unesite validan IBAN.",
6869
"uniqueErrorText": "Vrijednost mora biti jedinstvena.",
6970
"bicErrorText": "Unesite validan BIC.",

lib/l10n/intl_ca.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"containsErrorText": "El valor ha de contenir {value}.",
6565
"betweenErrorText": "El valor ha d'estar entre {min} i {max}.",
6666
"containsElementErrorText": "El valor ha d'estar en la llista de valors permesos.",
67+
"doesNotContainElementErrorText": "El valor no pot estar a la llista.",
6768
"ibanErrorText": "Aquest camp requereix un IBAN vàlid.",
6869
"uniqueErrorText": "Aquest camp requereix un valor únic.",
6970
"bicErrorText": "Aquest camp requereix un codi BIC vàlid.",

lib/l10n/intl_cs.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"containsErrorText": "Hodnota musí obsahovat {value}.",
6565
"betweenErrorText": "Hodnota musí být mezi {min} a {max}.",
6666
"containsElementErrorText": "Hodnota musí být v seznamu povolených hodnot.",
67+
"doesNotContainElementErrorText": "Hodnota nesmí být v seznamu.",
6768
"ibanErrorText": "Pole vyžaduje platné IBAN.",
6869
"uniqueErrorText": "Hodnota musí být jedinečná.",
6970
"bicErrorText": "Pole vyžaduje platný BIC kód.",

lib/l10n/intl_da.arb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"containsErrorText": "Værdien skal indeholde {value}.",
6565
"betweenErrorText": "Værdien skal være mellem {min} og {max}.",
6666
"containsElementErrorText": "Værdien skal være på listen over tilladte værdier.",
67+
"doesNotContainElementErrorText": "Værdien må ikke være på listen.",
6768
"ibanErrorText": "Dette felt kræver en gyldig IBAN.",
6869
"uniqueErrorText": "Dette felt skal være unikt.",
6970
"bicErrorText": "Dette felt kræver en gyldig BIC.",

0 commit comments

Comments
 (0)