如何限制 ExtJS DatePicker 中的两个日期?

发布于 2025-01-06 08:21:21 字数 112 浏览 1 评论 0原文

我在 ExtJS4 中有一个 DatePicker。我只想允许每个月有两个日期。第 15 天和最后一天(30/31/28/29,取决于月份/年份)

我如何禁用选择器中的每一天,但允许这两个日期?

I have a DatePicker in ExtJS4. I only want to allow TWO dates for each month. The 15th and last day (30/31/28/29 depending on month/year)

How can I disable every day in the picker but allow those two dates?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

辞取 2025-01-13 08:21:21

Ext.form.field.DatedisabledDates 配置选项

请参阅API 文档中

disabledDates : String[] 要禁用的“日期”数组,作为字符串。
这些字符串将用于构建动态正则表达式,因此
他们非常强大。一些例子:

// 禁用这些确切日期:
禁用日期:[“03/08/2003”,“09/16/2003”]
// 每年禁用这些天:
禁用日期:[“03/08”,“09/16”]
// 仅匹配开头(如果您使用短年份则很有用):
禁用日期:[“^03/08”]
// 禁用 2006 年 3 月的每一天:
禁用日期:[“03/../2006”]
// 禁用每年三月的每一天:
禁用日期:[“^03”]

请注意,数组中包含的日期格式应准确无误
匹配格式配置。为了支持正则表达式,if
您使用的日期格式包含“.”在其中,你必须
限制日期时转义点。例如:[“03\.08\.03”]。

See disabledDates config option for Ext.form.field.Date

From API docs:

disabledDates : String[] An array of "dates" to disable, as strings.
These strings will be used to build a dynamic regular expression so
they are very powerful. Some examples:

// disable these exact dates:
disabledDates: ["03/08/2003", "09/16/2003"]
// disable these days for every year:
disabledDates: ["03/08", "09/16"]
// only match the beginning (useful if you are using short years):
disabledDates: ["^03/08"]
// disable every day in March 2006:
disabledDates: ["03/../2006"]
// disable every day in every March:
disabledDates: ["^03"]

Note that the format of the dates included in the array should exactly
match the format config. In order to support regular expressions, if
you are using a date format that has "." in it, you will have to
escape the dot when restricting dates. For example: ["03\.08\.03"].

乖乖 2025-01-13 08:21:21
//Get the last date of the month. If in Feb 2012, lastDate is 29.
var lastDate = Ext.Date.getDaysInMonth(new Date());
//15th 
var middleDate = 15;

//Construct regular expression
var disabledArray=[];
var today = Ext.Date.format(new Date(), 'm/d/Y');
var dateReg = /(\d{2}\/)\d{2}(\/\d{4})/;
disabledArray.push(today.replace(dateReg, '$1' + middleDate + '$2'));
disabledArray.push(today.replace(dateReg, '$1' + lastDate + '$2'));

//Something like "^(?!02/15/2012|02/29/2012).*$" including the two days allowed.
var disabledReg = '^(?!' + disabledArray.join('|') + ').*
;

//Apply the regular expression to date field
var dateField = new Ext.form.field.Date({
    format: 'm/d/Y',
    disabledDates: [disabledReg]
});
//Get the last date of the month. If in Feb 2012, lastDate is 29.
var lastDate = Ext.Date.getDaysInMonth(new Date());
//15th 
var middleDate = 15;

//Construct regular expression
var disabledArray=[];
var today = Ext.Date.format(new Date(), 'm/d/Y');
var dateReg = /(\d{2}\/)\d{2}(\/\d{4})/;
disabledArray.push(today.replace(dateReg, '$1' + middleDate + '$2'));
disabledArray.push(today.replace(dateReg, '$1' + lastDate + '$2'));

//Something like "^(?!02/15/2012|02/29/2012).*$" including the two days allowed.
var disabledReg = '^(?!' + disabledArray.join('|') + ').*
;

//Apply the regular expression to date field
var dateField = new Ext.form.field.Date({
    format: 'm/d/Y',
    disabledDates: [disabledReg]
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文