You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README-updated.md
+32-36Lines changed: 32 additions & 36 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,14 +104,13 @@ Generally, we build a validator composing those three types in the following way
104
104
105
105
#### Equality validators
106
106
107
-
TODO remove every verb `is` from the name of the validators.
108
-
-`Validators.isEqual(value)`: Checks if the field contains an input that is equal to `value` (==).
109
-
-`Validators.isNotEqual(value)`: Checks if the field contains an input that is not equal to `value` (!=).
107
+
-`Validators.equal(value)`: Checks if the field contains an input that is equal to `value` (==).
108
+
-`Validators.notEqual(value)`: Checks if the field contains an input that is not equal to `value` (!=).
110
109
111
110
#### Required validators
112
111
113
-
-`Validators.isRequired(next)`: Makes the field required by checking if it contains a non-null and non-empty value, passing it to the `next` validator as a not-nullable type.
114
-
-`Validators.isOptional(next)`: Makes the field optional by passing it to the `next` validator if it contains a non-null and non-empty value. If the field is null or empty, null is returned.
112
+
-`Validators.required(next)`: Makes the field required by checking if it contains a non-null and non-empty value, passing it to the `next` validator as a not-nullable type.
113
+
-`Validators.optional(next)`: Makes the field optional by passing it to the `next` validator if it contains a non-null and non-empty value. If the field is null or empty, null is returned.
115
114
-`Validators.validateWithDefault(defaultValue, next)`: Validates the field with `next` validator. If the input is null, it uses the `defaultValue` instead.
116
115
117
116
#### Transform validators
@@ -120,10 +119,9 @@ TODO remove every verb `is` from the name of the validators.
120
119
121
120
### Datetime validators
122
121
123
-
-`Validators.isAfter(reference)`: Checks if the field contains a `DateTime` that is after `reference`.
124
-
-`Validators.isBefore(reference)`: Checks if the field contains a `DateTime` that is before `reference`.
125
-
TODO replace isDateTimeBetween with betweenDateTime
126
-
-`Validators.isDateTimeBetween(minReference, maxReference)`: Checks if the field contains a `DateTime` that is after `minReference` and before `maxReference`.
122
+
-`Validators.after(reference)`: Checks if the field contains a `DateTime` that is after `reference`.
123
+
-`Validators.before(reference)`: Checks if the field contains a `DateTime` that is before `reference`.
124
+
-`Validators.betweenDateTime(minReference, maxReference)`: Checks if the field contains a `DateTime` that is after `minReference` and before `maxReference`.
127
125
- TODO `FormBuilderValidators.date()` - requires the field's value to be a valid date string.
128
126
- TODO `FormBuilderValidators.time()` - requires the field's value to be a valid time string.
129
127
- TODO `FormBuilderValidators.timeZone()` - requires the field's value to be a valid time zone.
@@ -147,7 +145,7 @@ TODO replace isDateTimeBetween with betweenDateTime
147
145
### Generic Type Validators
148
146
Validators that check a generic type user input.
149
147
150
-
-`Validators.isInList(values)`: Checks if the field contains a value that is in the list `values`.
148
+
-`Validators.inList(values)`: Checks if the field contains a value that is in the list `values`.
151
149
-`Validators.isTrue()`: Checks if the field contains a boolean or a parsable `String` of the `true` value.
152
150
-`Validators.isFalse()`: Checks if the field contains a boolean or a parsable `String` of the `false` value.
153
151
@@ -209,12 +207,12 @@ Validators that check a generic type user input.
209
207
- TODO `FormBuilderValidators.singleLine()` - requires the field's string to be a single line of text.
210
208
211
209
### Type Validators
212
-
-`Validators.isString(next)`: Checks if the field contains a valid `String` and passes the input as `String` to the `next` validator.
213
-
-`Validators.isInt(next)`: Checks if the field contains a valid `int` or parsable `String` to `int` and passes the input as `int` to the `next` validator.
214
-
-`Validators.isDouble(next)`: Checks if the field contains a valid `double` or parsable `String` to `double` and passes the input as `double` to the `next` validator.
215
-
-`Validators.isNum(next)`: Checks if the field contains a valid `num` or parsable `String` to `num` and passes the input as `num` to the `next` validator.
216
-
-`Validators.isBool(next)`: Checks if the field contains a valid `bool` or parsable `String` to `bool` and passes the input as `bool` to the `next` validator.
217
-
-`Validators.isDateTime(next)`: Checks if the field contains a valid `DateTime` or parsable `String` to `DateTime` and passes the input as `DateTime` to the `next` validator.
210
+
-`Validators.string(next)`: Checks if the field contains a valid `String` and passes the input as `String` to the `next` validator.
211
+
-`Validators.int(next)`: Checks if the field contains a valid `int` or parsable `String` to `int` and passes the input as `int` to the `next` validator.
212
+
-`Validators.double(next)`: Checks if the field contains a valid `double` or parsable `String` to `double` and passes the input as `double` to the `next` validator.
213
+
-`Validators.num(next)`: Checks if the field contains a valid `num` or parsable `String` to `num` and passes the input as `num` to the `next` validator.
214
+
-`Validators.bool(next)`: Checks if the field contains a valid `bool` or parsable `String` to `bool` and passes the input as `bool` to the `next` validator.
215
+
-`Validators.dateTime(next)`: Checks if the field contains a valid `DateTime` or parsable `String` to `DateTime` and passes the input as `DateTime` to the `next` validator.
218
216
219
217
### User Information validators
220
218
@@ -316,7 +314,7 @@ return MaterialApp(
316
314
TextFormField(
317
315
decoration: InputDecoration(labelText: 'Name'),
318
316
autovalidateMode: AutovalidateMode.always,
319
-
validator: Validators.isRequired(),
317
+
validator: Validators.required(),
320
318
),
321
319
```
322
320
@@ -338,25 +336,23 @@ TextFormField(
338
336
decoration: InputDecoration(labelText: 'Age'),
339
337
keyboardType: TextInputType.number,
340
338
autovalidateMode: AutovalidateMode.always,
341
-
validator: FormBuilderValidators.compose([
342
-
/// Makes this field required
343
-
FormBuilderValidators.required(),
344
-
345
-
/// Ensures the value entered is numeric - with a custom error message
346
-
FormBuilderValidators.numeric(errorText: 'La edad debe ser numérica.'),
347
-
348
-
/// Sets a maximum value of 70
349
-
FormBuilderValidators.max(70),
339
+
validator: Validators.required(
340
+
Validators.and(<Validator<String>>[
341
+
Validators.num(Validators.lessThan(70), (_) => 'La edad debe ser numérica.'),
350
342
351
343
/// Include your own custom `FormFieldValidator` function, if you want
352
-
/// Ensures positive values only. We could also have used `FormBuilderValidators.min(0)` instead
353
-
(val) {
354
-
final number = int.tryParse(val);
355
-
if (number == null) return null;
356
-
if (number < 0) return 'We cannot have a negative age';
344
+
/// Ensures positive values only. We could also have used `Validators.greaterThanOrEqualTo(0)` instead
345
+
(String? val) {
346
+
if (val != null) {
347
+
final int? number = int.tryParse(val);
348
+
// todo bug here: if it is not int, it accepts negative
349
+
// numbers
350
+
if (number == null) return null;
351
+
if (number < 0) return 'We cannot have a negative age';
0 commit comments