Skip to content

Commit 47a3ef1

Browse files
committed
Check if value is String, Iterable / Map then check length - required
1 parent 37b9953 commit 47a3ef1

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [3.0.0-beta.6] - 07-April-2019
2+
* Check if value candidate is of type String, Iterable or Map before checking length to determine empty in `FormValidators.required`
3+
14
## [3.0.0-beta.6] - 09-April-2019
25
* Properly hooked up SignaturePad to form, added onChanged to it
36
* SignaturePad now returns `Uint8List` object from `png` image

lib/src/form_builder_validators.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class FormBuilderValidators {
66
static FormFieldValidator required({
77
String errorText = "This field cannot be empty.",
88
}) {
9-
return (val) {
10-
if (val == null || val.isEmpty) {
9+
return (val) { //FIXME: Change all val instances to valueCandidate
10+
if (val == null || ((val is Iterable || val is String || val is Map) && val.length == 0)) {
1111
return errorText;
1212
}
1313
};

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.6
3+
version: 3.0.0-beta.7
44
author: Danvick Miller <[email protected]>
55
homepage: https://github.com/danvick/flutter_form_builder
66

test/flutter_form_builder_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import 'package:test/test.dart';
22
import 'package:flutter_form_builder/flutter_form_builder.dart';
33

44
void main() {
5+
test('FormBuilderValidators.required', () {
6+
expect(FormBuilderValidators.required()("something long"), isNull);
7+
expect(FormBuilderValidators.required()(DateTime.now()), isNull);
8+
expect(FormBuilderValidators.required()(''), isNotNull);
9+
expect(FormBuilderValidators.required()([]), isNotNull);
10+
// expect(FormBuilderValidators.maxLength(5)(5), equals(null));
11+
});
12+
513
test('FormBuilderValidators.maxLength', () {
614
expect(FormBuilderValidators.maxLength(5)("something long"), equals("Value must have a length less than or equal to 5"));
715
expect(FormBuilderValidators.maxLength(5)("two"), equals(null));

0 commit comments

Comments
 (0)