@@ -51,18 +51,21 @@ DateTimeField = React.createClass({
5151 } ) ;
5252 } ,
5353 onChange : function ( event ) {
54- if ( moment ( event . target . value , this . props . format ) . isValid ( ) ) {
54+ if ( moment ( event . target . value , this . props . inputFormat ) . isValid ( ) ) {
5555 this . setState ( {
56- selectedDate : moment ( event . target . value , this . props . format ) ,
57- inputValue : moment ( event . target . value , this . props . format ) . format ( this . props . inputFormat )
56+ selectedDate : moment ( event . target . value , this . props . inputFormat ) ,
57+ viewDate : moment ( event . target . value , this . props . inputFormat ) . startOf ( "month" )
5858 } ) ;
59- } else {
60- this . setState ( {
61- inputValue : event . target . value
62- } ) ;
63- console . log ( "This is not a valid date" ) ;
6459 }
65- return this . props . onChange ( this . state . selectedDate . format ( this . props . format ) ) ;
60+
61+ return this . setState ( {
62+ inputValue : event . target . value
63+ } , function ( ) {
64+ console . log ( this . state . inputValue ) ;
65+ console . log ( moment ( this . state . inputValue , this . props . inputFormat , true ) . calendar ( ) ) ;
66+ return this . props . onChange ( moment ( this . state . inputValue , this . props . inputFormat , true ) . format ( this . props . format ) ) ;
67+ } ) ;
68+
6669 } ,
6770 setSelectedDate : function ( e ) {
6871 return this . setState ( {
@@ -285,7 +288,7 @@ DateTimeField = React.createClass({
285288 togglePeriod = { this . togglePeriod }
286289 />
287290 < div className = "input-group date" ref = "datetimepicker" >
288- < input type = "text" className = "form-control" onChange = { this . onChange } value = { this . state . selectedDate . format ( this . props . inputFormat ) } />
291+ < input type = "text" className = "form-control" onChange = { this . onChange } value = { this . state . inputValue } />
289292 < span className = "input-group-addon" onClick = { this . onClick } onBlur = { this . onBlur } ref = "dtpbutton" > < Glyphicon glyph = "calendar" /> </ span >
290293 </ div >
291294 </ div >
0 commit comments