admin管理员组

文章数量:1415111

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.

本文标签: javascriptDisable specific days in pcalendarStack Overflow