react-native-calendars icon indicating copy to clipboard operation
react-native-calendars copied to clipboard

mark multiple dates dynamically

Open sfm2222 opened this issue 8 years ago • 11 comments

Question

How to mark multiple dates dynamically. The below won't work as array cannot be directly assigned.

var nextDay =['2018-06-01',
       '2018-06-05',
       '2018-06-08',  
       '2018-06-07',
       '2018-06-18',
       '2018-06-17',
       '2018-05-28',
       '2018-05-29'];

   const mark = {
   	[nextDay]: {selected: true, marked: true}
   };

sfm2222 avatar May 29 '18 12:05 sfm2222

Answered your question here : https://stackoverflow.com/a/50597708/3840093

First of all you have to create an object of date and select string, and then add that state variable into your calendar element.

KirankumarDafda avatar May 30 '18 08:05 KirankumarDafda

@sfm2222 Did the provided solution work?

kinza88 avatar Jul 16 '18 07:07 kinza88

@KirankumarDafda i did the same as mentioned here https://stackoverflow.com/a/50597708/3840093 . all the dates retrieved from the server are marked. However I noticed that the ones marked are only those in 2018 and not 2019.

Any suggestion as to why this happens?

abn0rmal-d0ct0r avatar Jan 24 '19 07:01 abn0rmal-d0ct0r

I am currently working on this and my all marked dates are working fine, so you may need to check & confirm your date format or other details.

KirankumarDafda avatar Jan 25 '19 10:01 KirankumarDafda

What about dynamically marked dates with selected dates? How do I combine both?

helloitsm3 avatar Feb 13 '19 14:02 helloitsm3

What I am doing for this is load all dynamically marked dates first, create array of it, and then concat selected dates with its value one by one to the array of dynamically marked dates.

KirankumarDafda avatar Feb 27 '19 13:02 KirankumarDafda

Thank you. I manage to find a way to dynamically add the dates selected as well as the marked dates.

helloitsm3 avatar Feb 28 '19 03:02 helloitsm3

how to fetch dates dynamically and mark dates ,can anyone please put some reference code .

ramanasak avatar Oct 13 '19 13:10 ramanasak

how to fetch dates dynamically and mark dates, can anyone please put some reference code.

This is how I did it. I fetched my dates using Axios and store all marked dates in an array. Once it's stored, I assigned the marked: true to the dates and parse it as an object. It would look something like this.

this.setState({ booking_dates: [...this.state.booking_dates, booking.booking_date] })); } }).then(() => { const obj = this.state.booking_dates.reduce( (c, v) => Object.assign(c, { [v]: { selected: false, marked: true } }), {} ); this.setState({ marked: obj }); });

Once the object is stored in state, I'll call it to markedDates like this.

<Calendar markedDates={this.state.marked} />

Hope it helps.

helloitsm3 avatar Oct 14 '19 02:10 helloitsm3

how to fetch dates dynamically and mark dates, can anyone please put some reference code.

This is how I did it. I fetched my dates using Axios and store all marked dates in an array. Once it's stored, I assigned the marked: true to the dates and parse it as an object. It would look something like this.

this.setState({ booking_dates: [...this.state.booking_dates, booking.booking_date] })); } }).then(() => { const obj = this.state.booking_dates.reduce( (c, v) => Object.assign(c, { [v]: { selected: false, marked: true } }), {} ); this.setState({ marked: obj }); });

Once the object is stored in state, I'll call it to markedDates like this.

<Calendar markedDates={this.state.marked} />

Hope it helps.

Its works fine to me

rvmobiledev avatar Nov 23 '19 07:11 rvmobiledev

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Aug 22 '20 20:08 stale[bot]