Wednesday, 31 May 2017

DatePicker is not working in react.js

I have written a code in React.js for Datepicker but it's not working :

var DatePicker = React.createClass({

getInitialState: function () {
    return {
        currentDate: Moment().format('MM/DD/YYYY')
    };
},
prev: function () {
    var dateForHandler = new Date(this.state.currentDate);
    var dateForState = new Date(this.state.currentDate);
    this.props.dateHandler(dateForHandler.setDate(dateForHandler.getDate() - 7));
    this.setState({currentDate: Moment(dateForState.setDate(dateForState.getDate() - 7)).format('MM/DD/YYYY')});

},
next: function () {
    var dateForHandler = new Date(this.state.currentDate);
    var dateForState = new Date(this.state.currentDate);
    this.props.dateHandler(dateForHandler.setDate(dateForHandler.getDate() + 7));
    this.setState({currentDate: Moment(dateForState.setDate(dateForState.getDate() + 7)).format('MM/DD/YYYY')});

},
render: function () {
    var currentDate = this.state.currentDate;
    return (
        <div className="col-md-12 text-center mar_top_bottom">
            <Button text="" key="prev" click={this.prev} css="arrow_icon_backg arrow_left_icon pull-left"/>
            <p className="text_padding">{Moment().format('MM/DD/YYYY')==currentDate?'This Week':'Week of '+currentDate}</p>
            <Button text="" key="next" click={this.next} css="arrow_icon_backg arrow_right_icon pull-right"/>
        </div>
    );
},
componentDidMount: function () {

},
componentWillUnmount: function () {

}

I have created a contrl DatePicker.js. the above code is written on DatePicker.js.

And i am calling this datepicker on js page then datepicker will not come.



via Nidhi Tiwari

No comments:

Post a Comment