Closed greenafrican closed 9 years ago
Seems to work for me, are you sure you're formatting it correctly? It needs to be an actual date object.
...
earliest_date: new Date('December 1, 2014'),`
...
...
earliest_date: new Date("October 1, 2014"),
...
Screenshot - https://cloudup.com/c1zKpw7-jdH
Ahhh I see what you're saying. Yep that's an issue. Sorry 'bout that.
Just wondering what happened to this? Do you prefer to leave the presets unchanged?
@greenafrican Is it still an issue? I closed it forever ago. Are you still experiencing the problem in the latest update?
@tyvdh Sorry, I know this issue is updated. I'm now looking to update earliest_date
on the fly and have the presets update. I guess a method is needed. Would you like a PR?
@greenafrican I wouldn't merge it into the main repo since this isn't a core feature. All you really need to do is update the instance variable and then refresh the calendar. All of which you can already do.
@tyvdh Ok, thanks. What is the best way to refresh? .presetsCreate()
looks like it'll work.
Yep. What we use @Baremetrics is something to the flavor of:
calendar.start_date = moment().subtract(1, 'month');
calendar.end_date = moment();
calendar.calendarSetDates();
var range = moment(calendar.end_date).diff(calendar.start_date, 'days');
calendar.presets = presetArray(calendar, range);
calendar.presetCreate();
function presetArray(CalBase, range) {
return [{
label: 'Previous Period',
start: moment(CalBase.start_date).subtract(range + 1, 'days'),
end: moment(CalBase.end_date).subtract(range + 1, 'days')
},{
label: '3 months previous',
start: moment(CalBase.start_date).subtract(3, 'months'),
end: moment(CalBase.end_date).subtract(3, 'months')
},{
label: '6 months previous',
start: moment(CalBase.start_date).subtract(6, 'months'),
end: moment(CalBase.end_date).subtract(6, 'months')
},{
label: 'Previous year',
start: moment(CalBase.start_date).subtract(1, 'year'),
end: moment(CalBase.end_date).subtract(1, 'year')
}]
}
Good luck!
Do you mean:
calendar.settings.presets = presetArray(calendar, range);
Otherwise, .presetsCreate()
defaults the hard-coded presets?
Yeah. It would update your dates in the preset list I think though. Honestly I'm not 100% on exactly what does what. Been too long since I worked on that piece of it. Just fool around with a couple of the functions and see what they do. I do know you'll at least need to updat your default dates before redrawing any calendar HTML
Hello there,
Firstly, thanks for sharing an awesome calendar picker!
I've noticed that if I set the
earliest_date
to something like 1st Dec 2014 it isn't respected by the1 Year
preset (and others), which sets thestart_date
to 27 July 2014, for example.Ciao ;)