chrisdavies / tiny-date-picker

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

Disable days? #45

Closed Spunkie closed 7 years ago

Spunkie commented 7 years ago

Is it possible to disable entire days? For example I need to make a datepicker that does not allow weekends so I would want to disable every Saturday/Sunday in TinyDatePicker.

I tried adding .dp-day-disabled to the days alongside .dp-day but this only changed the styling while still allowing the days to be selected.

chrisdavies commented 7 years ago

Not right now, but it would be a minor change, and arguably a better design for some internal plumbing in the library.

I'll put it together this week.

On Jul 25, 2017 8:04 AM, "Spunkie" notifications@github.com wrote:

Is it possible to disable entire days? For example I need to make a datepicker that does not allow weekends so I would want to disable every Saturday/Sunday in TinyDatePicker.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/chrisdavies/tiny-date-picker/issues/45, or mute the thread https://github.com/notifications/unsubscribe-auth/AAy3Ydi6T9TNLPe96CY99soeX-26a3CDks5sRdnmgaJpZM4OidcP .

chrisdavies commented 7 years ago

Added. See the readme:

// Customizes what CSS class is associated with a particular date.
  // For example, to disable weekends:
  // dateClass(dt) {
  //   return (dt.getDay() % 6) ? '' : 'dp-day-disabled';
  // }
  dateClass: function (dt, context) {
    // dt is the date
    // context is the datepicker context
  }
Spunkie commented 7 years ago

I've tried out the new version and it does apply the css correctly to style the days as disabled but nothing actually prevents them from selecting the disabled days. So the disabled days are not really disabled.

chrisdavies commented 7 years ago

Ah. You're right. I thought I'd tested that, but was mistaken. I'm leaving the dateClass option in, since it seems useful, but I have added an inRange option, too. Again, see the readme. that should solve the problem!