diff --git a/lib/src/models/form_builder.dart b/lib/src/models/form_builder.dart index 52933d8..22a4352 100644 --- a/lib/src/models/form_builder.dart +++ b/lib/src/models/form_builder.dart @@ -244,9 +244,9 @@ class FormBuilder { } else if (value is double) { return FormControl(value: value, validators: validators); } else if (value is DateTime) { - return FormControl(value: value); + return FormControl(value: value, validators: validators); } else if (value is TimeOfDay) { - return FormControl(value: value); + return FormControl(value: value, validators: validators); } return FormControl(value: value, validators: validators); diff --git a/test/src/models/form_builder_test.dart b/test/src/models/form_builder_test.dart index cc26001..de9156a 100644 --- a/test/src/models/form_builder_test.dart +++ b/test/src/models/form_builder_test.dart @@ -411,6 +411,35 @@ void main() { ); }); + + test('Build a group with default datetime value and a validator as array', () { + // Given: a form group builder creation + final requiredValidator = Validators.required; + final value = DateTime.now(); + final form = fb.group({ + 'control': [value, requiredValidator], + }); + + // Expect a form group created + expect( + form.control('control'), + isA>(), + reason: + '${form.control('control').runtimeType} is not instance of FormControl', + ); + expect( + form.control('control').value, + value, + reason: 'control default value not set', + ); + expect( + form.control('control').validators, + [requiredValidator], + reason: 'not set required validator' + ); + }); + + test('Build a group with default TimeOfDay value as array', () { // Given: a form group builder creation final value = TimeOfDay.now(); @@ -432,6 +461,34 @@ void main() { ); }); + + test('Build a group with default TimeOfDay value and a validator as array', () { + // Given: a form group builder creation + final requiredValidator = Validators.required; + final value = TimeOfDay.now(); + final form = fb.group({ + 'control': [value, requiredValidator], + }); + + // Expect a form group created + expect( + form.control('control'), + isA>(), + reason: + '${form.control('control').runtimeType} is not instance of FormControl', + ); + expect( + form.control('control').value, + value, + reason: 'control default value not set', + ); + expect( + form.control('control').validators, + [requiredValidator], + reason: 'not set required validator' + ); + }); + test('Build a state with ', () { // Given: a state creation final state = fb.state(value: 'name', disabled: true);