bevacqua / rome

:calendar: Customizable date (and time) picker. Opt-in UI, no jQuery!
https://bevacqua.github.io/rome
MIT License
2.91k stars 223 forks source link

Passing back data with `dateValidator()` method and applying it to calendar? #142

Open arman-h opened 8 years ago

arman-h commented 8 years ago

Hello all,

First of all, thanks for the wonderful library. I have a question/feature request: is there a way to pass back additional data when using dateValidator (and, optionally, apply it to calendar cells)?

There are multiple use cases for this. One example is to pass back a string explaining why the date might be invalid (for example, it's already occupied with another event, or it's a holiday), which can be applied to calendar's td title attribute. Another example is to highlight a selected date range when using 2 calendars, in which case we could return an array of classes for dates that fall within the range.

For example, jQuery UI datepicker has a beforeShowDay() method, which allows sending classes to be applied to the given date. I've briefly looked through how dateValidator works, and as I understand, it only allows passing back a true/false/undefined values (indicating whether the date is valid), but no way to pass back additional data.

cllns commented 8 years ago

The way I got around this is by adding a listener to ready and month which selects all valid dates in that month by iterating over $('.rd-days td:not(.rd-day-disabled):not(.rd-day-next-month):not(.rd-day-prev-month)') If you want to include the few days in the adjacent months, get rid of next-month and prev-month.