javascript - Disable specific days in p:calendar? - Stack Overflow

I am working on Primefaces in JSF , i am just trying to disable all sundays in calendar,How can i do it

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 function tuesdaysAndFridaysDisabled

And it not working too.. How to achieve it and what is happening there..

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 function tuesdaysAndFridaysDisabled

And it not working too.. How to achieve it and what is happening there..

Share Improve this question asked Nov 21, 2013 at 6:40 karkkark 4,8536 gold badges32 silver badges44 bronze badges 1
  • Does this answer your question? Disable specific dates on p:calendar – Jasper de Vries Commented Mar 2, 2023 at 9:44
Add a ment  | 

1 Answer 1

Reset to default 4

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745216277a4617040.html

相关推荐

  • javascript - Disable specific days in p:calendar? - Stack Overflow

    I am working on Primefaces in JSF , i am just trying to disable all sundays in calendar,How can i do it

    4小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信