2
votes

is there an angular 2 datepicker component that enables me to disable an array of specific dates?

I know that creating a custom wrapper for jquery datepicker is an option.

I found these 3 datepickers, but no one seem to capable of disabling certain dates.

https://github.com/kekeh/mydatepicker

https://github.com/jkuri/ng2-datepicker

www.primefaces.org/primeng/#/calendar

EDIT:

I will be getting the list in an http request. In addition, I need to disable all dates before the current date.

EDIT2:

It is a reservation use case. I need to disable all dates before today and I need to disable all dates from an array I will get in an http request.

The usage of validator is not a good option, because the user needs to see what he cannot choose.

EDIT3:

I have just found this one https://github.com/valor-software/ng2-bootstrap/tree/master/components/datepicker, I will go with this one and later post an answer.

1
You can disable using jkuri if you modified the html they created. I used it before. - hdotluna
@Herm Luna see my edit - Michael.D

1 Answers

1
votes

This one has it. http://www.primefaces.org/primeng/#/calendar

See the Date Restriction section

<p-calendar [(ngModel)]="dateValue" minDate="-1m" maxDate="+1m" [readonlyInput]="true">></p-calendar>

+it uses jquery UI datepicker so you can use some of this: Jquery UI datepicker. Disable array of Dates

But...

Best way of doing this is probably just make an validator for this, and prevent user of selecting the value. You are 3rd party independent with this solution. Which can be pretty helpful in angular2 dynamic world.

AFTER QUESTION EDIT

I will be getting the list in an http request. In addition, I need to disable all dates before the current date.

If you don't want to code it in angular (validator or some change detection). The primeNG restrict will give you ability to disable a range of dates. (max/min date)