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: packages/form_builder_validators/README.md
+22-22Lines changed: 22 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# FormBuilder Validators
2
2
3
-
Form Builder Validators provide a convenient way of validating data entered into any Flutter FormField. It provides common validation rules out of box (such as required, email, number, min, max, minLength, maxLength, date validations etc.) as well as a way to compose multiple validation rules into one FormFieldValidator.
3
+
Form Builder Validators provide a convenient way of validating data entered into any Flutter FormField. It offers common validation rules out of the box (such as required, email, number, min, max, minLength, maxLength, date validations, etc.) and a way to compose multiple validation rules into one FormFieldValidator.
4
4
5
-
Also included is the `l10n` / `i18n` of error text messages into multiple languages
5
+
Also included is the `l10n` / `i18n` of error text messages to multiple languages.
[](https://www.buymeacoffee.com/danvick)
16
16
___
17
17
18
+
> ### Migrating from version 7 to 8
19
+
> To migrate from v7 to v8, remove `context` as a parameter to validator functions. For example, `FormBuilderValidators.required(context)` becomes `FormBuilderValidators.required()` without context passed to it.
*`FormBuilderValidators.creditCard()` - requires the field's value to be a valid credit card number.
@@ -64,10 +67,9 @@ Available built-in validators include:
64
67
*``FormBuilderValidators.url()`` - requires the field's value to be a valid url.
65
68
66
69
## Composing multiple validators
67
-
`FormBuilderValidators` class comes with a very useful static function named `compose()` which takes a list of `FormFieldValidator` functions. This allows you to create once and reuse validation rules across multiple fields, widgets or apps.
70
+
`FormBuilderValidators` class comes with a very useful static function named `compose()` which takes a list of `FormFieldValidator` functions. Composing allows you to create once and reuse validation rules across multiple fields, widgets, or apps.
68
71
69
-
On validation each validator is run and if any one returns a non-null value (i.e. a String), validation fails and the `errorText` for the field is set as the
70
-
returned string.
72
+
On validation, each validator is run, and if any one validator returns a non-null value (i.e., a String), validation fails, and the `errorText` for the field is set as the returned string.
71
73
72
74
Example:
73
75
```dart
@@ -77,17 +79,16 @@ TextFormField(
77
79
autovalidateMode: AutovalidateMode.always,
78
80
validator: FormBuilderValidators.compose([
79
81
/// Makes this field required
80
-
FormBuilderValidators.required(context),
82
+
FormBuilderValidators.required(),
81
83
82
84
/// Ensures the value entered is numeric - with custom error message
83
-
FormBuilderValidators.numeric(context,
84
-
errorText: 'La edad debe ser numérica.'),
85
+
FormBuilderValidators.numeric(errorText: 'La edad debe ser numérica.'),
85
86
86
87
/// Sets a maximum value of 70
87
-
FormBuilderValidators.max(context, 70),
88
+
FormBuilderValidators.max(70),
88
89
89
90
/// Include your own custom `FormFieldValidator` function, if you want
90
-
/// Ensures positive values only. We could also have used `FormBuilderValidators.min(context, 0)` instead
91
+
/// Ensures positive values only. We could also have used `FormBuilderValidators.min(0)` instead
91
92
(val) {
92
93
final number = int.tryParse(val);
93
94
if (number == null) return null;
@@ -144,31 +145,31 @@ To allow for localization of default error messages within your app, add `FormBu
144
145
- Swahili (sw)
145
146
- Ukrainian (uk)
146
147
147
-
and you can still add your own custom error messages.
148
+
And you can still add your custom error messages.
148
149
149
150
## Support
150
151
### Issues and PRs
151
-
Any kind of support in the form of reporting bugs, answering questions or PRs is always appreciated.
152
+
Any support in reporting bugs, answering questions, or PRs is always appreciated.
152
153
153
154
We especially welcome efforts to internationalize/localize the package by translating the default validation `errorText` strings for built-in validation rules.
154
155
155
156
### Localizing messages
156
157
157
158
#### 1. Add ARB files
158
-
Create one ARB file inside the `lib/l10n` folder for each of the locales you need to add support for. Name the files in the following way: `intl_<LOCALE_ISO_CODE>.arb`. For example: `intl_fr.arb` or `intl_fr_FR.arb`.
159
+
Create one ARB file inside the `lib/l10n` folder for each of the locales you need to add support. Name the files in the following way: `intl_<LOCALE_ISO_CODE>.arb`. For example: `intl_fr.arb` or `intl_fr_FR.arb`.
159
160
160
161
#### 2. Translate the error messages
161
162
162
-
Duplicate the contents of `intl_messages.arb` (or any other ARB file) into your newly created ARB file then translate the error messages by overwritting the default messages.
163
+
Duplicate the contents of `intl_messages.arb` (or any other ARB file) into your newly created ARB file, then translate the error messages by overwriting the default messages.
163
164
164
165
#### 3. Run command
165
-
To generate boilerplate code for localization, run the generate command inside package directory where `pubspec.yaml` file is located:
166
+
To generate boilerplate code for localization, run the generate command inside the package directory where `pubspec.yaml` file is located:
166
167
167
168
```
168
169
flutter pub run intl_utils:generate
169
170
```
170
171
171
-
This will automagically create/update files inside `lib/localization` directory which will include support for your newly added locale.
172
+
Running the command will automatically create/update files inside the `lib/localization` directory, including your newly added locale support.
172
173
173
174
#### 4. Update README
174
175
Remember to update README, adding the new language (and language code) under [Supported languages section](#supported-languages-default-errortext-messages) so that everyone knows your new language is now supported!
@@ -177,8 +178,7 @@ Remember to update README, adding the new language (and language code) under [Su
177
178
Submit your PR and be of help to millions of developers all over the world!
178
179
179
180
### Coffee :-)
180
-
If this package was helpful to you in delivering your project or you just wanna to support this
181
-
package, a cup of coffee would be highly appreciated ;-)
181
+
If this package was helpful to you in delivering your project, or you want to support this package, I would highly appreciate a cup of coffee ;-)
182
182
183
183
[](https://www.buymeacoffee.com/danvick)
0 commit comments