限制日期选择器中的多个日期 [英] Restrict multiple dates in date picker

查看:40
本文介绍了限制日期选择器中的多个日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日历,并且希望禁用植物素日期,正在使用 https://www.primefaces.org/primeng/#/calendar

I have a calendar and I want certanin dates to be disabled, am using https://www.primefaces.org/primeng/#/calendar

在html中我有这个

<p-calendar formControlName="date"  [inline]="true" [disabledDates]="restictedBookingDates"  [minDate]="minimumDate" tabindex="0" readonlyInput="true">
                <ng-template pTemplate="date" let-date>
                    <span [ngStyle]="{backgroundColor: (date.day ==10) ? '#7cc67c' : 'inherit'}"   style="border-radius:50%">{{date.day}}</span>
                </ng-template>
            </p-calendar>

我拥有的计算机

 restictedBookingDates: Array<Date>; 

 ngOnInit() {
    const today = new Date();
    const invalidDate = new Date();
    invalidDate.setDate(today.getDate() - 1);
    this.restictedBookingDates = [today, invalidDate];
  }

这仅限制今天的日期,我希望能够限制多个日期,例如

This restrict only todays date, I want to be able to restrict multiple dates eg

var restictedBookingDates= ["7-15-2018", "7-23-2018", "7-23-2018"];

我需要更改我的代码以完成我想要的东西吗?

what do I need to change in my code to acomplish what I want?

推荐答案

创建一个限制日期数组,如下所示:

Create an array of your restricted dates, like so:

restrictedBookingDates = [
    new Date(2018, 6, 23),
    new Date(2018, 6, 17)
];

这将限制7月23日至17日的预订.请注意,月份选项从零开始,所以6代表七月.

This would restrict bookings on the 23rd and 17th of July. Please note that the month options is zero based, so 6 represents July.

这是一个StackBlitz示例

这篇关于限制日期选择器中的多个日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆