@@ -22,6 +22,22 @@ var DATEPICKER_TEMPLATE =
22
22
'ng-disabled="isDisabled">' +
23
23
'</md-datepicker>' ;
24
24
25
+ var DATEPICKER_FORM_TEMPLATE =
26
+ '<form name="birthdayForm">' +
27
+ ' <md-datepicker name="birthday" ' +
28
+ ' md-max-date="maxDate" ' +
29
+ ' md-min-date="minDate" ' +
30
+ ' md-date-filter="dateFilter" ' +
31
+ ' md-month-filter="monthFilter" ' +
32
+ ' ng-model="myDate" ' +
33
+ ' ng-change="dateChangedHandler()" ' +
34
+ ' ng-focus="focusHandler()" ' +
35
+ ' ng-blur="blurHandler()" ' +
36
+ ' ng-required="isRequired" ' +
37
+ ' ng-disabled="isDisabled">' +
38
+ ' </md-datepicker>' +
39
+ '</form>' ;
40
+
25
41
/**
26
42
* Compile and link the given template and store values for element, scope, and controller.
27
43
* @param {string } template
@@ -135,6 +151,35 @@ describe('md-datepicker', function() {
135
151
} ) . not . toThrow ( ) ;
136
152
} ) ;
137
153
154
+ it ( 'should support null, undefined, and values that can be parsed into a date in a form' ,
155
+ function ( ) {
156
+ var formElement = createDatepickerInstance ( DATEPICKER_FORM_TEMPLATE ) ;
157
+ var datepickerInputContainer =
158
+ formElement [ 0 ] . querySelector ( 'md-datepicker .md-datepicker-input-container' ) ;
159
+
160
+ pageScope . myDate = null ;
161
+ pageScope . $apply ( ) ;
162
+ $timeout . flush ( ) ;
163
+ expect ( datepickerInputContainer . classList . contains ( 'md-datepicker-invalid' ) ) . toBeFalsy ( ) ;
164
+
165
+ pageScope . myDate = undefined ;
166
+ pageScope . $apply ( ) ;
167
+ $timeout . flush ( ) ;
168
+ expect ( datepickerInputContainer . classList . contains ( 'md-datepicker-invalid' ) ) . toBeFalsy ( ) ;
169
+
170
+ pageScope . myDate = '2016-09-08' ;
171
+ pageScope . $apply ( ) ;
172
+ $timeout . flush ( ) ;
173
+ expect ( pageScope . myDate ) . toEqual ( '2016-09-08' ) ;
174
+ expect ( datepickerInputContainer . classList . contains ( 'md-datepicker-invalid' ) ) . toBeFalsy ( ) ;
175
+
176
+ pageScope . myDate = '2021-01-20T07:00:00Z' ;
177
+ pageScope . $apply ( ) ;
178
+ $timeout . flush ( ) ;
179
+ expect ( pageScope . myDate ) . toEqual ( '2021-01-20T07:00:00Z' ) ;
180
+ expect ( datepickerInputContainer . classList . contains ( 'md-datepicker-invalid' ) ) . toBeFalsy ( ) ;
181
+ } ) ;
182
+
138
183
it ( 'should set the element type as "date"' , function ( ) {
139
184
expect ( ngElement . attr ( 'type' ) ) . toBe ( 'date' ) ;
140
185
} ) ;
@@ -448,7 +493,7 @@ describe('md-datepicker', function() {
448
493
expect ( controller . ngModelCtrl . $touched ) . toBe ( true ) ;
449
494
} ) ;
450
495
451
- it ( 'should not update the input string is not "complete"' , function ( ) {
496
+ it ( 'should not update the input string if not "complete"' , function ( ) {
452
497
var date = new Date ( 2015 , DEC , 1 ) ;
453
498
pageScope . myDate = date ;
454
499
0 commit comments