在p:日历中禁用特定日期? [英] Disable specific days in p:calendar?
问题描述
我正在使用JSF中的 Primefaces
,我只是想在日历中禁用所有星期日,
我怎么能这样做,
- 正如我提到的网站,我得到了一个点,我们可以使用
在事实日之前实现它
但我不知道如何使用它。 -
Primefaces用户指南第10页解释了这一点,但我不明白他们想说什么。
< p:calendar value =#{dateBean.date}beforeShowDay =tuesdaysAndFridaysOnly/>
function tuesdaysAndFridaysDisabled(date)
{
var day = date.getDay();
返回[(day!= 2&& day!= 5),'']
}
在上面的代码中,他们从调用函数
但我的问题是 tuesdaysAndFridaysDisabled
beforeShowDay
- 他们正在调用函数名称
tuesdaysAndFridaysOnly
但它将如何影响该功能tuesdaysAndFridaysDisabled
并且它不工作..如何实现它以及那里发生的事情..
这是Primefaces文档中的错误。应该调用它们的函数 tuesdaysAndFridaysDisabled
而不是 tuesdaysAndFridaysOnly
,这是一个javascript函数,你可以调用它来自定义日期。 / p>
所以正确的源代码看起来像
< p: calendar value =#{dateBean.date}beforeShowDay =tuesdaysAndFridaysDisabled/>
在函数 tuesdaysAndFridaysDisabled
中你可以做随你提供的参数日期你想要什么。在这种情况下,周二( 2
)和周五( 5
)被禁用。
function tuesdaysAndFridaysDisabled(date)
{
var day = date.getDay();
返回[(day!= 2&& day!= 5),'']
}
文档说明:
该函数返回一个包含两个值的数组,第一个是$ b的标志$ b表示日期是否显示为启用,第二个参数是
要添加到日期单元格的可选样式类。
正如你所看到的。如果日期
是星期二或星期五,则返回数组中的第一个参数是 false
,这意味着这些天将不会在 p:calendar
中选择。
更新:
您可以在此处找到类似的问题:禁用p:calendar上的特定日期。
I am working on Primefaces
in JSF , i am just trying to disable all sundays in calendar,
How can i do it,,
- As i referred sites, i got a point we can achieve it using
beforeShowDay
but i don't know how to use it. Primefaces user guide page 10 explains it, but i don't understand what they trying to say.
<p:calendar value="#{dateBean.date}" beforeShowDay="tuesdaysAndFridaysOnly" /> function tuesdaysAndFridaysDisabled(date) { var day = date.getDay(); return [(day != 2 && day != 5), ''] }
In above code they are calling the function tuesdaysAndFridaysDisabled
from beforeShowDay
but my question is
- They are calling the function name as
tuesdaysAndFridaysOnly
but how it will affect the functiontuesdaysAndFridaysDisabled
And it not working too.. How to achieve it and what is happening there..
This is an error in the Primefaces documentation. They function tuesdaysAndFridaysDisabled
should be called instead of tuesdaysAndFridaysOnly
, which is a javascript function you can call to customize the date.
So the correct source code would look like
<p:calendar value="#{dateBean.date}" beforeShowDay="tuesdaysAndFridaysDisabled" />
And within the function tuesdaysAndFridaysDisabled
you can do whatever you want with the provided parameter date. In this case the tuesdays (2
) and fridays (5
) are disabled.
function tuesdaysAndFridaysDisabled(date)
{
var day = date.getDay();
return [(day != 2 && day != 5), '']
}
The documentation states:
The function returns an array with two values, first one is flag to indicate if date would be displayed as enabled and second parameter is the optional style class to add to date cell.
As you can see. If the date
is a tuesday or friday, the first parameter in the returned array is false
, which means that these days won't be selected within the p:calendar
.
Update: You can find a similar question here: Disable specific dates on p:calendar.
这篇关于在p:日历中禁用特定日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!