@@ -38,31 +38,31 @@ DateTimeField = React.createClass({
3838 left : - 9999 ,
3939 zIndex : '9999 !important'
4040 } ,
41- viewDate : moment ( this . props . dateTime , this . props . format ) . startOf ( "month" ) ,
42- selectedDate : moment ( this . props . dateTime , this . props . format ) ,
43- inputValue : moment ( this . props . dateTime , this . props . format ) . format ( this . props . inputFormat )
41+ viewDate : moment ( this . props . dateTime , this . props . format , true ) . startOf ( "month" ) ,
42+ selectedDate : moment ( this . props . dateTime , this . props . format , true ) ,
43+ inputValue : moment ( this . props . dateTime , this . props . format , true ) . format ( this . props . inputFormat )
4444 } ;
4545 } ,
4646 componentWillReceiveProps : function ( nextProps ) {
47- return this . setState ( {
48- viewDate : moment ( nextProps . dateTime , nextProps . format ) . startOf ( "month" ) ,
49- selectedDate : moment ( nextProps . dateTime , nextProps . format ) ,
50- inputValue : moment ( nextProps . dateTime , nextProps . format ) . format ( nextProps . inputFormat )
51- } ) ;
47+ if ( moment ( nextProps . dateTime , nextProps . format , true ) . isValid ( ) ) {
48+ return this . setState ( {
49+ viewDate : moment ( nextProps . dateTime , nextProps . format , true ) . startOf ( "month" ) ,
50+ selectedDate : moment ( nextProps . dateTime , nextProps . format , true ) ,
51+ inputValue : moment ( nextProps . dateTime , nextProps . format , true ) . format ( nextProps . inputFormat )
52+ } ) ;
53+ }
5254 } ,
5355 onChange : function ( event ) {
54- if ( moment ( event . target . value , this . props . inputFormat ) . isValid ( ) ) {
56+ if ( moment ( event . target . value , this . props . inputFormat , true ) . isValid ( ) ) {
5557 this . setState ( {
56- selectedDate : moment ( event . target . value , this . props . inputFormat ) ,
57- viewDate : moment ( event . target . value , this . props . inputFormat ) . startOf ( "month" )
58+ selectedDate : moment ( event . target . value , this . props . inputFormat , true ) ,
59+ viewDate : moment ( event . target . value , this . props . inputFormat , true ) . startOf ( "month" )
5860 } ) ;
5961 }
6062
6163 return this . setState ( {
6264 inputValue : event . target . value
6365 } , function ( ) {
64- console . log ( this . state . inputValue ) ;
65- console . log ( moment ( this . state . inputValue , this . props . inputFormat , true ) . calendar ( ) ) ;
6666 return this . props . onChange ( moment ( this . state . inputValue , this . props . inputFormat , true ) . format ( this . props . format ) ) ;
6767 } ) ;
6868
0 commit comments