@@ -514,6 +514,7 @@ function($compile, $parse, $document, $rootScope, $position, dateFilter, datePar
514
514
onOpenFocus = angular . isDefined ( attrs . onOpenFocus ) ? scope . $parent . $eval ( attrs . onOpenFocus ) : datepickerPopupConfig . onOpenFocus ,
515
515
datepickerPopupTemplateUrl = angular . isDefined ( attrs . datepickerPopupTemplateUrl ) ? attrs . datepickerPopupTemplateUrl : datepickerPopupConfig . datepickerPopupTemplateUrl ,
516
516
datepickerTemplateUrl = angular . isDefined ( attrs . datepickerTemplateUrl ) ? attrs . datepickerTemplateUrl : datepickerPopupConfig . datepickerTemplateUrl ,
517
+ timelessJsonMode = angular . isDefined ( attrs . timelessJsonMode ) ? attrs . timelessJsonMode : datepickerPopupConfig . timelessJsonMode ,
517
518
cache = { } ;
518
519
519
520
scope . showButtonBar = angular . isDefined ( attrs . showButtonBar ) ? scope . $parent . $eval ( attrs . showButtonBar ) : datepickerPopupConfig . showButtonBar ;
@@ -535,6 +536,19 @@ function($compile, $parse, $document, $rootScope, $position, dateFilter, datePar
535
536
return ( new Date ( date1 . getFullYear ( ) , date1 . getMonth ( ) , date1 . getDate ( ) ) - new Date ( date2 . getFullYear ( ) , date2 . getMonth ( ) , date2 . getDate ( ) ) ) ;
536
537
} ;
537
538
539
+ scope . jsonToDate = function ( date ) {
540
+ if ( date && angular . isString ( date ) && date . indexOf ( '-' ) > - 1 ) {
541
+ var update = date . indexOf ( 'T' ) > - 1 ;
542
+ date = date . substring ( 0 , 10 ) . split ( '-' ) ;
543
+ date = new Date ( + date [ 0 ] , + date [ 1 ] - 1 , + date [ 2 ] ) ;
544
+ if ( update ) {
545
+ ngModel . $setViewValue ( dateFilter ( date , dateFormat ) ) ;
546
+ ngModel . $render ( ) ;
547
+ }
548
+ }
549
+ return date ;
550
+ } ;
551
+
538
552
var isHtml5DateInput = false ;
539
553
if ( datepickerPopupConfig . html5Types [ attrs . type ] ) {
540
554
dateFormat = datepickerPopupConfig . html5Types [ attrs . type ] ;
@@ -649,15 +663,15 @@ function($compile, $parse, $document, $rootScope, $position, dateFilter, datePar
649
663
if ( isNaN ( date ) ) {
650
664
return undefined ;
651
665
} else {
652
- return date ;
666
+ return timelessJsonMode ? dateFilter ( date , 'yyyy-MM-dd' ) : date ;
653
667
}
654
668
} else {
655
669
return undefined ;
656
670
}
657
671
}
658
672
659
673
function validator ( modelValue , viewValue ) {
660
- var value = modelValue || viewValue ;
674
+ var value = ( timelessJsonMode ? scope . jsonToDate ( modelValue ) : modelValue ) || viewValue ;
661
675
662
676
if ( ! attrs . ngRequired && ! value ) {
663
677
return true ;
@@ -684,11 +698,17 @@ function($compile, $parse, $document, $rootScope, $position, dateFilter, datePar
684
698
ngModel . $validators . date = validator ;
685
699
ngModel . $parsers . unshift ( parseDate ) ;
686
700
ngModel . $formatters . push ( function ( value ) {
701
+ if ( timelessJsonMode ) {
702
+ value = scope . jsonToDate ( value ) ;
703
+ }
687
704
scope . date = value ;
688
705
return ngModel . $isEmpty ( value ) ? value : dateFilter ( value , dateFormat ) ;
689
706
} ) ;
690
707
} else {
691
708
ngModel . $formatters . push ( function ( value ) {
709
+ if ( timelessJsonMode ) {
710
+ value = scope . jsonToDate ( value ) ;
711
+ }
692
712
scope . date = value ;
693
713
return value ;
694
714
} ) ;
0 commit comments