chrisdavies / tiny-date-picker

A small, modern, dependency-free date picker
https://chrisdavies.github.io/tiny-date-picker/
415 stars 87 forks source link

expose render function, or inRange callback, or... #49

Closed trvsdnn closed 7 years ago

trvsdnn commented 7 years ago

Nice job on the date picker. I really like the simplicity.

Seems like a common use case could be to make an ajax call when the year, or month changes to determine which days should be enabled or disabled. Currently, not seeing a great way to do this, although I could just be missing it.

I've exposed the mode render function to the picker. I'm making an ajax call when state changes, updating a cache of available days, re-rendering, and checking the cache in the inRange function. It works, but there's the obvious visual glitch of days showing and then being disabled.

Just wondering 1) if there's any reason not to expose render, and 2) is there a better way to accomplish this maybe something with the inRange function?

chrisdavies commented 7 years ago

Thanks! Yeah. The API doesn't currently support promises, so there's not a great way to do this. I'm assuming that you've got logic to detect when the month has changed.

So, the best workaround I can think of is to do something like this:

trvsdnn commented 7 years ago

Thanks, I'll try this and a few other approaches I've been thinking of. I was sorta assuming you didn't want to introduce promises in unless you have to... and I'd tend to agree with that.

chrisdavies commented 7 years ago

Yeah. The disable / enable workaround would probably look less distracting if you added a CSS transition for the transition from disabled -> enabled. Just a thought. Please let me know what you end up doing. I'll add it to the wiki when you do.

Good luck!