File tree 2 files changed +34
-1
lines changed 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -418,4 +418,24 @@ describe('DatePicker', () => {
418
418
} ) ;
419
419
expect ( vm . validMultipleType ) . toBe ( false ) ;
420
420
} ) ;
421
+
422
+ it ( 'If the value entered manually is in the disabled range should be invalid' , ( ) => {
423
+ const someday = new Date ( 2020 , 6 , 1 ) ;
424
+ wrapper = shallowMount ( DatePicker , {
425
+ format : 'YYYY-MM-DD' ,
426
+ propsData : {
427
+ disabledDate : date => {
428
+ return date < someday ;
429
+ } ,
430
+ } ,
431
+ } ) ;
432
+ const textInput = wrapper . find ( 'input' ) ;
433
+ textInput . setValue ( '2020-08-01' ) ;
434
+ textInput . trigger ( 'change' ) ;
435
+ expect ( wrapper . emitted ( ) . input [ 0 ] [ 0 ] ) . toEqual ( new Date ( 2020 , 7 , 1 ) ) ;
436
+ textInput . setValue ( '2020-05-01' ) ;
437
+ textInput . trigger ( 'change' ) ;
438
+ expect ( wrapper . emitted ( ) . input [ 1 ] ) . toBe ( undefined ) ;
439
+ expect ( wrapper . emitted ( ) [ 'input-error' ] [ 0 ] [ 0 ] ) . toBe ( '2020-05-01' ) ;
440
+ } ) ;
421
441
} ) ;
Original file line number Diff line number Diff line change @@ -396,6 +396,19 @@ export default {
396
396
}
397
397
return isValidDate (value);
398
398
},
399
+ isValidValueAndNotDisabled (value ) {
400
+ if (! this .isValidValue (value)) {
401
+ return false ;
402
+ }
403
+ const disabledDate =
404
+ typeof this .disabledDate === ' function' ? this .disabledDate : () => false ;
405
+ const disabledTime =
406
+ typeof this .disabledTime === ' function' ? this .disabledTime : () => false ;
407
+ if (! Array .isArray (value)) {
408
+ value = [value];
409
+ }
410
+ return value .every (v => ! disabledDate (v) && ! disabledTime (v));
411
+ },
399
412
handleMultipleDates (date , dates ) {
400
413
if (this .validMultipleType && dates) {
401
414
const nextDates = dates .filter (v => v .getTime () !== date .getTime ());
@@ -470,7 +483,7 @@ export default {
470
483
} else {
471
484
date = this .parseDate (text, this .format );
472
485
}
473
- if (this .isValidValue (date)) {
486
+ if (this .isValidValueAndNotDisabled (date)) {
474
487
this .emitValue (date);
475
488
this .blur ();
476
489
} else {
You can’t perform that action at this time.
0 commit comments