Airbnb react date range picker only showing current month calendar not selected dates month calender

Web Technologies Web Development 2 years ago

0 1 0 0 0

_x000D_ _x000D_ I'm trying to add airbnb-react-date. After selecting start date and end date when I am re-opening the date picker the calendar shows current month instead of the selected start date/end date's month. For example: If I set start date = 2017-05-05 and end date = 2017-05-09 then it shows the selected date, but if I click again the calendar picker opens and it only shows current month i.e February calendar, that's why I have to click the next month, next month to see the previous selected dates i.e May; How I implemented: From https://github.com/airbnb/react-dates#getting-started Installed npm install --save react-dates moment@>=#.## react@>=#.## react-dom@>=#.## react-addons-shallow-compare@>=#.## I have installed required node packages i.e babel, webpack. Every time I run command webpack on the project directory to build the bundle.js and then run index.html to see the output. index.html

Initial date picker

entry.js import React from 'react'; import ReactDOM from 'react-dom'; import moment from 'moment'; import { DateRangePicker } from 'react-dates'; var SelectedStartDate = moment('2017-05-05'); var SelectedEndDate = moment('2017-05-09'); class HomePageDatePicker extends React.Component { constructor(props) { super(props); this.state = { focusedInput: null, startDate: SelectedStartDate, endDate:SelectedEndDate }; this.onDatesChange = this.onDatesChange.bind(this); this.onFocusChange = this.onFocusChange.bind(this); } onDatesChange({ startDate, endDate }) { this.setState({ startDate, endDate }); } onFocusChange(focusedInput) { this.setState({ focusedInput }); } render() { const { focusedInput, startDate, endDate } = this.state; return (
); } } ReactDOM.render( , document.getElementById('mydatepicker') ); webpack.config.js module.exports = { entry: "./entry.js", output: { path: __dirname, filename: "bundle.js" }, module: { loaders: [ { test: /\.css$/, loader: "style!css" }, { test: /\.(js|jsx)$/, exclude: /(node_modules|bower_components)/, loader: 'babel-loader', query: { presets: ['es2015', 'stage-0', 'react'], plugins: ['transform-runtime'] } } ] } }; What I Have: What I Need:

Posted on 16 Aug 2022, this text provides information on Web Development related to Web Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ as stated in react-dates storybook you can do this with initialVisibleMonth={endDate} on the render function. import React from 'react'; import ReactDOM from 'react-dom'; import moment from 'moment'; import { DateRangePicker } from 'react-dates'; var SelectedStartDate = moment('2017-05-05'); var SelectedEndDate = moment('2017-05-09'); class HomePageDatePicker extends React.Component { constructor(props) { super(props); this.state = { focusedInput: null, startDate: SelectedStartDate, endDate:SelectedEndDate }; this.onDatesChange = this.onDatesChange.bind(this); this.onFocusChange = this.onFocusChange.bind(this); } onDatesChange({ startDate, endDate }) { this.setState({ startDate, endDate }); } onFocusChange(focusedInput) { this.setState({ focusedInput }); } render() { const { focusedInput, startDate, endDate } = this.state; return (
); } } ReactDOM.render( , document.getElementById('mydatepicker') );
0 views
0 shares

No matter what stage you're at in your education or career, TuteeHUB will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Similar Forum


Q

Unity hosting a custom piece of code on own website [on hold]

_x000D_ _x000D_ I was wondering how would you be able to host an "API" on your own website that you...
Q

I am needing advice on a web bot [on hold]

_x000D_ _x000D_ I want to code a bot that has a GUI or CLI doesn't really matter yet but a GUI would...
Q

date and time picker, that can take a max and min absolute time, compatible with react [on hold]

_x000D_ _x000D_ I have an issue with scheduling things in a web platform (react.js), and need a date...

Important Web Technologies Links