5 Replies Latest reply on Dec 3, 2010 5:15 PM by cmathrusse

    Preventing certain days from being selected with rich:calendar

    cmathrusse

      I'm using RichFaces 4.0.0.20101110-M4 and I am trying to prevent the user from selecting any days on the calendar except for Mondays. I've found some sample code that I modified that seems to work well in disabling all days except for Mondays, but does not prevent the user from selecting those days.

       

      xhtml:

       

      <script type="text/javascript">

      function isDayEnabled(day){

        var date = new Date(day.date);

        return (date.getDay() == 1); // 1 is Monday, the only day that should be enabled.

      }

      function getDisabledStyle(day){

        if (!isDayEnabled(day)) return 'rich-calendar-boundary-dates disabledDay';

      }

      </script>

      <style>

      .disabledDay{

                     background-color:gray;

      }

      </style>

       

                      <rich:calendar id="cal-start-date"

                          value="#{quote.startDate}" requiredMessage="Date 1 is required."

                          datePattern="MMM d, yyyy" isDayEnabled="isDayEnabled"

                          dayStyleClass="getDisabledStyle"

                                  required="true" firstWeekDay="0"

                                  showWeeksBar="false">

                      </rich:calendar>

       

       

      But as you can see from the screenshot below, Mondays are the only days enabled but I can still select any day of the week.


       

      So how do I prevent the user from selecting all days except for Mondays?

       

      Thanks for the help...