Skip to content

Commit e6f11fa

Browse files
committed
Added changelog and example for conditional validation
1 parent 22ffd6c commit e6f11fa

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [3.0.0-beta.9] - 15-April-2019
2+
* Added property `fields` to FormBuilder, gives access to the current state of each field through a Map of `GlobalKey<FormFieldState<dynamic>>`s.
3+
This gives us access to the underlying FormField which in turn allows us:
4+
* Do conditional validation based on other fields (check readme)
5+
* Dynamically update field values
6+
17
## [3.0.0-beta.8] - 10-April-2019
28
* Fixed unhandled exception when `valueTransformer` tries to convert value from predefined `FormField` type
39

README.md

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ To use this plugin, add `flutter_form_builder` as a [dependency in your pubspec.
99

1010
### Example
1111
```dart
12-
final GlobalKey<FormBuilderState> _fbKey = GlobalKey();
12+
final GlobalKey<FormBuilderState> _fbKey = GlobalKey<FormBuilderState>();
1313
```
1414
**Note:** Avoid defining the GlobalKey inside your build method because this will create a new GlobalKey on every build cycle bringing about some erratic behavior.
1515

@@ -186,7 +186,6 @@ In order to create an input field in the form, along with the label, and any app
186186
| `validators` | `List<FormFieldValidator>` | `[]` | `false` | List of `FormFieldValidator`s that will check the validity of value candidate in the `FormField` |
187187
| `onChanged` | `ValueChanged<T>` | `null` | `false` | This event function will fire immediately the the field value changes |
188188
| `valueTransformer` | `ValueTransformer<T>` | `null` | `false` | Function that transforms field value before saving to form value. e.g. transform TextField value for numeric field from `String` to `num` |
189-
190189
The rest of the attributes will be determined by the type of Widget being used.
191190

192191
### Building your own custom `FormField`
@@ -261,16 +260,55 @@ FormBuilderTextField(
261260
),
262261
```
263262

263+
### Conditional validation
264+
You can now validate a field based on the value of another field
265+
```
266+
FormBuilderRadio(
267+
decoration: InputDecoration(labelText: 'My best language'),
268+
attribute: "best_language",
269+
validators: [FormBuilderValidators.required()],
270+
options: [
271+
"Dart",
272+
"Kotlin",
273+
"Java",
274+
"Swift",
275+
"Objective-C",
276+
"Other"
277+
]
278+
.map((lang) => FormBuilderFieldOption(value: lang))
279+
.toList(growable: false),
280+
),
281+
FormBuilderTextField(
282+
attribute: "specify",
283+
decoration: InputDecoration(labelText: "If Other, please specify"),
284+
validators: [
285+
(val){
286+
if(_fbKey.currentState.fields['best_language'].currentState.value == "Other" && (val == null || val.isEmpty))
287+
return "Kindly specify your language";
288+
},
289+
],
290+
),
291+
```
292+
293+
## CREDITS
294+
This package is dependent on the following packages and plugins:
295+
* [flutter_typeahead](https://pub.dartlang.org/packages/flutter_typeahead) by [https://github.com/AbdulRahmanAlHamali](https://github.com/AbdulRahmanAlHamali)
296+
* [sy_flutter_widgets]((https://pub.dartlang.org/packages/sy_flutter_widgets)) by [Li Shuhao](https://github.com/lishuhao)
297+
* [datetime_picker_formfield](https://pub.dartlang.org/packages/datetime_picker_formfield) by [Jacob Phillips](https://github.com/jifalops)
298+
* [flutter_chips_input](https://pub.dartlang.org/packages/flutter_chips_input) by [Yours trully :)](https://github.com/danvick)
299+
* [intl](https://pub.dartlang.org/packages/intl)
300+
* The SignaturePad is based on [signature](https://pub.dartlang.org/packages/signature) by [4Q s.r.o.](https://github.com/4Q-s-r-o) with some minor improvements to fit our usage
301+
264302
## TODO:
265303
### Improvements
266304
- [X] Allow addition of custom input types
267305
- [X] Improve documentation by showing complete list of input types and their usage and options
268-
- [ ] Create a `transformer` function option that will convert field value when field id saved - can be used to convert string to number, change to uppercase etc.
269-
- [ ] Assert no duplicates in `FormBuilderInput`s `attribute` names
306+
- [X] Create a `transformer` function option that will convert field value when field id saved - can be used to convert string to number, change to uppercase etc.
307+
- [X] Assert no duplicates in `FormBuilderInput`s `attribute` names
270308
- [ ] Allow options for Checkboxes and Radios to appear left or right
271309

272310
### New FormBuilder inputs
273-
- [X] SignaturePad
311+
- [X] SignaturePad - Based on [https://pub.dartlang.org/packages/signature](https://pub.dartlang.org/packages/signature)
274312
- [ ] MapInput
275313
- [ ] ImagePicker
276314
- [ ] DocumentPicker

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class MyHomePageState extends State<MyHomePage> {
3232
bool autoValidate = true;
3333
bool readOnly = false;
3434
bool showSegmentedControl = true;
35-
final GlobalKey<FormBuilderState> _fbKey = GlobalKey();
35+
final GlobalKey<FormBuilderState> _fbKey = GlobalKey<FormBuilderState>();
3636

3737
ValueChanged _onChanged = (val) => print(val);
3838

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_form_builder
22
description: Package to build Material Form with components such as TextField (With number, url, email validation), DropDown, TypeAhead, Radios, Checkboxes
3-
version: 3.0.0-beta.8
3+
version: 3.0.0-beta.9
44
author: Danvick Miller <[email protected]>
55
homepage: https://github.com/danvick/flutter_form_builder
66

0 commit comments

Comments
 (0)