Skip to content

Commit

Permalink
chore: released v6.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
danvick committed Sep 1, 2021
1 parent 2d95e82 commit 79d8898
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## [6.1.0] - 01-Sep-2021
* When form validation fails, automatically scroll to first error
* New way to programmatically induce custom errors by calling `GlobalKey<FormBuilderState>.invalidateField()` or `GlobalKey<FormBuilderFieldState>.invalidate()`
* Added Arabic and Persian/Farsi locales
* Made maxLines property nullable and added assertions
* Remove field from internal value map on when a field is unregistered
* Fix checkbox issue with null values

## [6.0.1] - 19-May-2021
* Add whitespace check for required validator
* Null-safety and type fixes
Expand Down
38 changes: 37 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,42 @@ FormBuilderTextField(
```

### Programmatically inducing an error
#### Option 1 - Using FormBuilder / FieldBuilderField key
```dart
final _formKey = GlobalKey<FormBuilderState>();
final _emailFieldKey = GlobalKey<FormBuilderFieldState>();
...
FormBuilder(
key: _formKey,
child: Column(
children: [
FormBuilderTextField(
key: _emailFieldKey
name: 'email',
decoration: InputDecoration(labelText: 'Email'),
validator: FormBuilderValidators.compose([
FormBuilderValidators.required(context),
FormBuilderValidators.email(context),
]),
),
RaisedButton(
child: Text('Submit'),
onPressed: () async {
if(await checkIfEmailExists()){
// Either invalidate using Form Key
_formKey.currentState?.invalidateField(name: 'email', errorText: 'Email already taken.');
// OR invalidate using Field Key
_emailFieldKey.currentState?.invalidate('Email already taken.');
}
},
),
],
),
),
```

#### Option 2 - Using InputDecoration.errorText
Declare a variable to hold your error:
```dart
String _emailError;
Expand All @@ -400,7 +436,7 @@ RaisedButton(
child: Text('Submit'),
onPressed: () async {
setState(() => _emailError = null);
if(checkIfEmailExists()){
if(await checkIfEmailExists()){
setState(() => _emailError = 'Email already taken.');
}
},
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_form_builder
description: This package helps in creation of forms in Flutter by removing the boilerplate code, reusing validation, react to changes, and collect final user input.
version: 6.0.1
version: 6.1.0
homepage: https://github.com/danvick/flutter_form_builder

environment:
Expand Down

0 comments on commit 79d8898

Please sign in to comment.