@@ -51,18 +51,21 @@ DateTimeField = React.createClass({
51
51
} ) ;
52
52
} ,
53
53
onChange : function ( event ) {
54
- if ( moment ( event . target . value , this . props . format ) . isValid ( ) ) {
54
+ if ( moment ( event . target . value , this . props . inputFormat ) . isValid ( ) ) {
55
55
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" )
58
58
} ) ;
59
- } else {
60
- this . setState ( {
61
- inputValue : event . target . value
62
- } ) ;
63
- console . log ( "This is not a valid date" ) ;
64
59
}
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
+
66
69
} ,
67
70
setSelectedDate : function ( e ) {
68
71
return this . setState ( {
@@ -285,7 +288,7 @@ DateTimeField = React.createClass({
285
288
togglePeriod = { this . togglePeriod }
286
289
/>
287
290
< 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 } />
289
292
< span className = "input-group-addon" onClick = { this . onClick } onBlur = { this . onBlur } ref = "dtpbutton" > < Glyphicon glyph = "calendar" /> </ span >
290
293
</ div >
291
294
</ div >
0 commit comments