Skip to content

Commit 330caf4

Browse files
Add the first migration instructions
1 parent ee762d7 commit 330caf4

File tree

2 files changed

+156
-10
lines changed

2 files changed

+156
-10
lines changed

README-updated.md

Lines changed: 148 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,157 @@ TextFormField(
365365
see [override_form_builder_localizations_en](example/lib/override_form_builder_localizations_en.dart) for more detail.
366366

367367
## Migrations
368-
369368
### v11 to v12
370369
- Deprecate `FormBuilderValidators` class with its static methods as validators.
371370
- Instead, you should use `Validators` class.
372-
TODO implement the remaining of breaking changes
371+
- Instructions on how to update each old API validator to the new API equivalent:
372+
- **checkNullOrEmpty**: Before specifying the equivalent to each validator, it is important to deal with the `checkNullOrEmpty` parameter. Every validator from the old API has this parameters, thus we are going to use this section to specify how to handle this situation for most of the cases and we will assume that this aspect is already handled for the following sections:
373+
- `checkNullOrEmpty = true`: Given the old api: `FormBuilderValidators.someValidator(..., checkNullOrEmpty:true)`, the equivalent in the new API is `Validators.required(Validators.someEquivalentValidator(...))`.
374+
- `checkNullOrEmpty = false`: Given the old api: `FormBuilderValidators.someValidator(..., checkNullOrEmpty:false)`, the equivalent in the new API is `Validators.optional(Validators.someEquivalentValidator(...))`.
375+
- Bool validators
376+
- For this group of validators, it is expected to receive a `String` as user input. Thus, if your
377+
form widget does not guarantee a `String` input (it may receive an `Object`), you must wrap the
378+
equivalent validator with the type validator for strings. Thus, instead of
379+
`Validators.hasMin<Something>Chars(...)`, use `Validators.string(Validators.hasMin<Something>Chars(...))`
380+
- `FormBuilderValidators.hasLowercaseChars(atLeast: n, regex: reg, errorText: 'some error')` is
381+
equivalent to `Validators.hasMinLowercaseChars(min: n, customLowercaseCounter:(input)=>reg.allMatches(input).length, hasMinLowercaseCharsMsg:(_, __)=>'some error')`
382+
- `FormBuilderValidators.hasNumericChars(atLeast: n, regex: reg, errorText: 'some error')` is
383+
equivalent to `Validators.hasMinNumericChars(min: n, customNumericCounter:(input)=>reg.allMatches(input).length, hasMinNumericCharsMsg:(_, __)=>'some error')`
384+
- `FormBuilderValidators.hasSpecialChars(atLeast: n, regex: reg, errorText: 'some error')` is
385+
equivalent to `Validators.hasMinSpecialChars(min: n, customSpecialCounter:(input)=>reg.allMatches(input).length, hasMinSpecialCharsMsg:(_, __)=>'some error')`
386+
- `FormBuilderValidators.hasUppercaseChars(atLeast: n, regex: reg, errorText: 'some error')` is
387+
equivalent to `Validators.hasMinUppercaseChars(min: n, customUppercaseCounter:(input)=>reg.allMatches(input).length, hasMinUppercaseCharsMsg:(_, __)=>'some error')`
388+
389+
<<<<<<<<<<<<<<<CONTINUE THE TODO>>>>>>>>>>>>>>>
390+
- `FormBuilderValidators.isFalse()` - requires the field's to be false.
391+
- `FormBuilderValidators.isTrue()` - requires the field's to be true.
392+
393+
### Collection validators
394+
395+
- `FormBuilderValidators.containsElement()` - requires the field's to be in the provided list.
396+
- `FormBuilderValidators.equalLength()` - requires the length of the field's value to be equal to the provided minimum length.
397+
- `FormBuilderValidators.maxLength()` - requires the length of the field's value to be less than or equal to the provided maximum size.
398+
- `FormBuilderValidators.minLength()` - requires the length of the field's value to be greater than or equal to the provided minimum length.
399+
- `FormBuilderValidators.range()` - requires the field's to be within a range.
400+
- `FormBuilderValidators.unique()` - requires the field's to be unique in the provided list.
401+
402+
### Core validators
403+
404+
- `FormBuilderValidators.aggregate()` - runs the validators in parallel, collecting all errors.
405+
- `FormBuilderValidators.compose()` - runs each validator against the value provided.
406+
- `FormBuilderValidators.conditional()` - conditionally runs a validator against the value provided.
407+
- `FormBuilderValidators.defaultValue()` - runs the validator using the default value when the provided value is null.
408+
- `FormBuilderValidators.equal()` - requires the field's value to be equal to the provided object.
409+
- `FormBuilderValidators.log()` - runs the validator and logs the value at a specific point in the validation chain.
410+
- `FormBuilderValidators.notEqual()` - requires the field's value to be not equal to the provided object.
411+
- `FormBuilderValidators.or()` - runs each validator against the value provided and passes when any works.
412+
- `FormBuilderValidators.required()` - requires the field to have a non-empty value.
413+
- `FormBuilderValidators.skipWhen()` - runs the validator and skips the validation when a certain condition is met.
414+
- `FormBuilderValidators.transform()` - transforms the value before running the validator.
415+
416+
### Datetime validators
417+
418+
- `FormBuilderValidators.dateFuture()` - requires the field's value to be in the future.
419+
- `FormBuilderValidators.datePast()` - requires the field's value to be a in the past.
420+
- `FormBuilderValidators.dateRange()` - requires the field's value to be a within a date range.
421+
- `FormBuilderValidators.dateTime()` - requires the field's value to be a valid date time.
422+
- `FormBuilderValidators.date()` - requires the field's value to be a valid date string.
423+
- `FormBuilderValidators.time()` - requires the field's value to be a valid time string.
424+
- `FormBuilderValidators.timeZone()` - requires the field's value to be a valid time zone.
425+
426+
### File validators
427+
428+
- `FormBuilderValidators.fileExtension()` - requires the field's value to a valid file extension.
429+
- `FormBuilderValidators.fileName()` - requires the field's to be a valid file name.
430+
- `FormBuilderValidators.fileSize()` - requires the field's to be less than the max size.
431+
- `FormBuilderValidators.mimeType()` - requires the field's value to a valid MIME type.
432+
- `FormBuilderValidators.path()` - requires the field's to be a valid file or folder path.
433+
434+
### Finance validators
435+
436+
- `FormBuilderValidators.bic()` - requires the field's to be a valid BIC.
437+
- `FormBuilderValidators.creditCardCVC()` - requires the field's value to be a valid credit card CVC number.
438+
- `FormBuilderValidators.creditCardExpirationDate()` - requires the field's value to be a valid credit card expiration date and can check if not expired yet.
439+
- `FormBuilderValidators.creditCard()` - requires the field's value to be a valid credit card number.
440+
- `FormBuilderValidators.iban()` - requires the field's to be a valid IBAN.
441+
442+
### Identity validators
443+
444+
- `FormBuilderValidators.city()` - requires the field's value to be a valid city name.
445+
- `FormBuilderValidators.country()` - requires the field's value to be a valid country name.
446+
- `FormBuilderValidators.firstName()` - requires the field's value to be a valid first name.
447+
- `FormBuilderValidators.lastName()` - requires the field's value to be a valid last name.
448+
- `FormBuilderValidators.passportNumber()` - requires the field's value to be a valid passport number.
449+
- `FormBuilderValidators.password()` - requires the field's to be a valid password that matched required conditions.
450+
- `FormBuilderValidators.ssn()` - requires the field's to be a valid SSN (Social Security Number).
451+
- `FormBuilderValidators.state()` - requires the field's value to be a valid state name.
452+
- `FormBuilderValidators.street()` - requires the field's value to be a valid street name.
453+
- `FormBuilderValidators.username()` - requires the field's to be a valid username that matched required conditions.
454+
- `FormBuilderValidators.zipCode()` - requires the field's to be a valid zip code.
455+
456+
### Network validators
457+
458+
- `FormBuilderValidators.email()` - requires the field's value to be a valid email address.
459+
- `FormBuilderValidators.ip()` - requires the field's value to be a valid IP address.
460+
- `FormBuilderValidators.latitude()` - requires the field's to be a valid latitude.
461+
- `FormBuilderValidators.longitude()` - requires the field's to be a valid longitude.
462+
- `FormBuilderValidators.macAddress()` - requires the field's to be a valid MAC address.
463+
- `FormBuilderValidators.phoneNumber()` - requires the field's value to be a valid phone number.
464+
- `FormBuilderValidators.portNumber()` - requires the field's to be a valid port number.
465+
- `FormBuilderValidators.url()` - requires the field's value to be a valid URL.
466+
467+
### Numeric validators
468+
469+
- `FormBuilderValidators.between()` - requires the field's to be between two numbers.
470+
- `FormBuilderValidators.evenNumber()` - requires the field's to be an even number.
471+
- `FormBuilderValidators.integer()` - requires the field's value to be an integer.
472+
- `FormBuilderValidators.max()` - requires the field's value to be less than or equal to the provided number.
473+
- `FormBuilderValidators.min()` - requires the field's value to be greater than or equal to the provided number.
474+
- `FormBuilderValidators.negativeNumber()` - requires the field's to be a negative number.
475+
- `FormBuilderValidators.notZeroNumber()` - requires the field's to be not a number zero.
476+
- `FormBuilderValidators.numeric()` - requires the field's value to be a valid number.
477+
- `FormBuilderValidators.oddNumber()` - requires the field's to be an odd number.
478+
- `FormBuilderValidators.positiveNumber()` - requires the field's to be a positive number.
479+
- `FormBuilderValidators.prime()` - requires the field's to be a prime number.
480+
481+
### String validators
482+
483+
- `FormBuilderValidators.alphabetical()` - requires the field's to contain only alphabetical characters.
484+
- `FormBuilderValidators.contains()` - requires the substring to be in the field's value.
485+
- `FormBuilderValidators.endsWith()` - requires the substring to be the end of the field's value.
486+
- `FormBuilderValidators.lowercase()` - requires the field's value to be lowercase.
487+
- `FormBuilderValidators.matchNot()` - requires the field's value to not match the provided regex pattern.
488+
- `FormBuilderValidators.match()` - requires the field's value to match the provided regex pattern.
489+
- `FormBuilderValidators.maxWordsCount()` - requires the word count of the field's value to be less than or equal to the provided maximum count.
490+
- `FormBuilderValidators.minWordsCount()` - requires the word count of the field's value to be greater than or equal to the provided minimum count.
491+
- `FormBuilderValidators.singleLine()` - requires the field's string to be a single line of text.
492+
- `FormBuilderValidators.startsWith()` - requires the substring to be the start of the field's value.
493+
- `FormBuilderValidators.uppercase()` - requires the field's value to be uppercase.
494+
495+
### Use-case validators
496+
497+
- `FormBuilderValidators.base64()` - requires the field's to be a valid base64 string.
498+
- `FormBuilderValidators.colorCode()` - requires the field's value to be a valid color code.
499+
- `FormBuilderValidators.duns()` - requires the field's value to be a valid DUNS.
500+
- `FormBuilderValidators.isbn()` - requires the field's to be a valid ISBN.
501+
- `FormBuilderValidators.json()` - requires the field's to be a valid json string.
502+
- `FormBuilderValidators.languageCode()` - requires the field's to be a valid language code.
503+
- `FormBuilderValidators.licensePlate()` - requires the field's to be a valid license plate.
504+
- `FormBuilderValidators.uuid()` - requires the field's to be a valid uuid.
505+
- `FormBuilderValidators.vin()` - requires the field's to be a valid VIN number.
506+
507+
### Extension method validators
508+
509+
Used for chaining and combining multiple validators.
510+
511+
- `FormBuilderValidator.and()` - Combines the current validator with another validator using logical AND.
512+
- `FormBuilderValidator.or()` - Combines the current validator with another validator using logical OR.
513+
- `FormBuilderValidator.when()` - Adds a condition to apply the validator only if the condition is met.
514+
- `FormBuilderValidator.unless()` - Adds a condition to apply the validator only if the condition is not met.
515+
- `FormBuilderValidator.transform()` - Transforms the value before applying the validator.
516+
- `FormBuilderValidator.skipWhen()` - Skips the validator if the condition is met.
517+
- `FormBuilderValidator.log()` - Logs the value during the validation process.
518+
- `FormBuilderValidator.withErrorMessage()` - Overrides the error message of the current validator.
373519

374520
### v10 to v11
375521

lib/src/form_builder_validators.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2768,7 +2768,7 @@ final class Validators {
27682768
/// {@endtemplate}
27692769
static Validator<String> hasMinUppercaseChars({
27702770
c.int min = 1,
2771-
c.int Function(String)? customUppercaseCounter,
2771+
c.int Function(String input)? customUppercaseCounter,
27722772
String Function(String input, c.int min)? hasMinUppercaseCharsMsg,
27732773
}) =>
27742774
val.hasMinUppercaseChars(
@@ -2789,9 +2789,9 @@ final class Validators {
27892789
/// ## Parameters
27902790
/// - `min` (`int`): The minimum number of lowercase characters required. Defaults
27912791
/// to 1.
2792-
/// - `customLowercaseCounter` (`int Function(String)?`): Optional custom function
2793-
/// to count lowercase characters. If not provided, uses a default Unicode-based
2794-
/// counter.
2792+
/// - `customLowercaseCounter` (`int Function(String input)?`): Optional custom function
2793+
/// to count lowercase characters. It receives the user input as parameter.
2794+
/// If not provided, uses a default Unicode-based counter.
27952795
/// - `hasMinLowercaseCharsMsg` (`String Function(String input, int min)?`):
27962796
/// Optional function to generate custom error messages. Receives the input and
27972797
/// the minimum lowercase count required and returns an error message string.
@@ -2829,7 +2829,7 @@ final class Validators {
28292829
/// {@endtemplate}
28302830
static Validator<String> hasMinLowercaseChars({
28312831
c.int min = 1,
2832-
c.int Function(String)? customLowercaseCounter,
2832+
c.int Function(String input)? customLowercaseCounter,
28332833
String Function(String input, c.int min)? hasMinLowercaseCharsMsg,
28342834
}) =>
28352835
val.hasMinLowercaseChars(
@@ -2850,7 +2850,7 @@ final class Validators {
28502850
/// ## Parameters
28512851
/// - `min` (`int`): The minimum number of numeric characters required. Defaults
28522852
/// to 1.
2853-
/// - `customNumericCounter` (`int Function(String)?`): Optional custom function
2853+
/// - `customNumericCounter` (`int Function(String input)?`): Optional custom function
28542854
/// to count numeric characters. If not provided, uses a default regex-based
28552855
/// counter matching digits 0-9.
28562856
/// - `hasMinNumericCharsMsg` (`String Function(String input, int min)?`):
@@ -2895,7 +2895,7 @@ final class Validators {
28952895
/// {@endtemplate}
28962896
static Validator<String> hasMinNumericChars({
28972897
c.int min = 1,
2898-
c.int Function(String)? customNumericCounter,
2898+
c.int Function(String input)? customNumericCounter,
28992899
String Function(String input, c.int min)? hasMinNumericCharsMsg,
29002900
}) =>
29012901
val.hasMinNumericChars(
@@ -2962,7 +2962,7 @@ final class Validators {
29622962
/// {@endtemplate}
29632963
static Validator<String> hasMinSpecialChars({
29642964
c.int min = 1,
2965-
c.int Function(String)? customSpecialCounter,
2965+
c.int Function(String input)? customSpecialCounter,
29662966
String Function(String input, c.int min)? hasMinSpecialCharsMsg,
29672967
}) =>
29682968
val.hasMinSpecialChars(

0 commit comments

Comments
 (0)