4 Replies Latest reply on Mar 3, 2011 7:06 AM by dasago

    Unable to select the current date in calendar

    Vishwanath Bannur Newbie

      Hi,

       

      I have created calendar component with disabling the previous dates from current date. The code is as follows.

      Here i am not able to select the current date. How to disable only previous dates and enable to select other dates in a month including current date.

       

      Code:

       

      <style>

              .everyThirdDay{

                  background-color:gray;

                 

              }

              .weekendBold{

                  font-weight:bold;

                  font-style: italic;

              }

             

          </style>

          <script type="text/javascript">

              var curDt = new Date();

              function disablementFunction(day){

                  if (day.isWeekend) return false;

                  if (curDt==undefined){

                      curDt = day.date.getDate;

                  }

                  if (curDt.getTime() - day.date.getTime() &lt; 0) return true; else return false; 

              }

              function disabledClassesProv(day){

                  if (curDt.getTime() - day.date.getTime() &gt;= 0) return 'rich-calendar-boundary-dates';

                  var res = '';

                  if (day.isWeekend) res+='weekendBold ';

                  if (day.day%3==0) res+='everyThirdDay';

                  return res;

              }

          </script>

          <rich:calendar isDayEnabled="disablementFunction" dayStyleClass="disabledClassesProv" boundaryDatesMode="scroll"/>

        • 2. Unable to select the current date in calendar
          Ilya Shaikovsky Master

          just change the confion in JS

           

          if (curDt.getTime() - day.date.getTime() &lt;= 0) return true; else return false;


          • 3. Unable to select the current date in calendar
            Vishwanath Bannur Newbie

            Hi ILya,

             

            I already tried putting '=' operator, but no luck. Here is the code please let me know i have missed anything.

             

            <script type="text/javascript">

                    var curDt = new Date();

                    function disablementFunction(day){

                        if (curDt.getTime() - day.date.getTime() &lt;= 0) return true; else return false;

                    }

                    function disabledClassesProv(day){

                    }

                </script>

             

            <h:form>

                <rich:calendar isDayEnabled="disablementFunction" dayStyleClass="disabledClassesProv" boundaryDatesMode="scroll"/>

            </h:form>

            • 4. Re: Unable to select the current date in calendar
              dasago Newbie

              Hi,

               

              it's not a good solution, but it works:

               

              <script type="text/javascript">

                      var curDt = new Date();

               

                      function disablementFunction(day){

                          //check if current date is available

                          if (curDt==undefined){

                              curDt = new Date();

                          }

               

                          var curDate = "" + curDt.getFullYear() + curDt.getMonth()+ curDt.getDate();

                          var dayDate = "" + day.date.getFullYear() + day.date.getMonth()+ day.date.getDate();

                          //enable current date

                          if(curDate - dayDate == 0) return true;

                          //enable future dates

                          if (curDt.getTime() - day.date.getTime() &lt; 0) return true; else return false; 

                      }

              </script>