Pat Ko
Pat Ko

Reputation: 159

Bootstrap Datepicker maximum selection of N days

I've got datepicker with option multidate and I want to define maximum days which user can select, for example 5 days, other days should be disabled. It should happen dynamically - user can select arbitrary 5 days and then other days should be blocked. How can I do that ?

Upvotes: 0

Views: 1775

Answers (1)

cfnerd
cfnerd

Reputation: 3799

Based on the documentation for the bootstrap-datepicker plugin you are using, it looks like if you just do multidate: 5 "the picker will limit how many dates can be selected to that number, dropping the oldest dates from the list when the number is exceeded."

$('#datepicker').datepicker({
      multidate: 5
});

As for disabling the days once 5 are selected, rather than dropping the oldest...I am not sure if that is possible. You might be able to do something like this (but not sure, as you would have to pass in a big array of dates):

$('#datepicker').datepicker({
      multidate: 5
}).on('changeDate', function(e){
    //some function here to disable dates once 5 are selected
});

Hope this helps.

Upvotes: 4

Related Questions