在 p:calendar 上禁用特定日期 [英] Disable specific dates on p:calendar
问题描述
是否可以在 PrimeFaces 3.5
组件上禁用特定日期(例如:5 月 15 日或 6 月 23 日)?有最小值和最大值,但我需要禁用特定日期,例如公共假期使用 el 表达式,以便我可以使用动态日期.
Is it possible to disable specific dates (for example: 15th May or 23rd June) on the PrimeFaces 3.5 <p:calendar>
component? There is min and max, but I need to disable specific dates like public holidays using el expressions so I can use dynamic dates.
使用 Hieu 的回答,确保您禁用的日期前面没有前导零(例如,03/03/2013"应为3/3/2013").
Using Hieu's answer, make sure the dates you disable have NO leading zeros in front (eg. '03/03/2013' should be '3/3/2013').
推荐答案
第一步:编写一个javascript函数来禁用日期列表
Step 1: write a javascript function to disable a list of dates
var disabledDays = ["5-15-2013", "6-23-2013"];
function disableAllTheseDays(date) {
var m = date.getMonth(), d = date.getDate(), y = date.getFullYear();
for (i = 0; i < disabledDays.length; i++) {
if($.inArray((m+1) + '-' + d + '-' + y,disabledDays) != -1) {
return [false];
}
}
return [true];
}
第2步:使用Primefaces datepicker的beforeShowDay
属性
Step 2: use beforeShowDay
attribute of Primefaces datepicker
<p:calendar id="pfdate" navigator="true" pattern="MM-dd-yyyy"
value="#{day}" beforeShowDay="disableAllTheseDays" showOn="button"/>
这篇关于在 p:calendar 上禁用特定日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!