6 Replies Latest reply on May 30, 2011 6:24 AM by garytxo

    Rich Calender isDayEnabled works only once

    mrras

      hello,

      I'm having a problem with isDayEnabled attribute.

      I want to have 2 calenders for start date and end date. I want start date to be chosen only from dates smaller than endDate, and vice versa. also both should not be chosen after today.

       

      my code works fine the first time. the js function is running multiple times when I first open each calendar pop up.

      the problem occur when I change one of the fields, and open the other field popup. apperantly the function doesn't run again and the days enabled/disabled do not change.

       

      any Idea on how to force the enablement function to run again?

       

      btw I use version 3.3.3.Final.

       

      this is my code:

       

      jsf:

       

      {code}

      <rich:calendar id="startDate" value="#{selectorsMB.startDate}" isDayEnabled="dayEnabledStart" cellWidth="24px" cellHeight="22px"/>

      <rich:calendar id="endDate" value="#{selectorsMB.endDate}" isDayEnabled="dayEnabledEnd" cellWidth="24px" cellHeight="22px""/>

      {code}

       

      js:

       

      {code}

      function dayEnabledStart(day){

          var currentEndDate = Richfaces.getComponent('calendar',document.getElementById("selectors:selectorsform:endDate")).getSelectedDate()

          var possibleStartDate = day.date;

          var today = new Date();

          today.setHours(0, 0, 0, 0);

          //all is ready.

          var test1 = dates.compare(possibleStartDate,currentEndDate);

          var test2 = dates.compare(possibleStartDate,today);

       

       

          if (test1 != 1 && test2 == -1)

          {

              return true;

          }

          else

          {

              return false;

          }

      }

      {code}

        • 1. Rich Calender isDayEnabled works only once
          mrras

          Any ideas about this one?

          • 2. Re: Rich Calender isDayEnabled works only once
            ilya_shaikovsky

            calendar performs markup calculation only once. And it can't know that something changed on the page and it need to re-evaluate the markup. Let's me look to the code slightly later in order to check if you could trigger such update manually.

             

            easiest way to perform re-render.. but that is not probably optimal to use request to server for pure client operation.

            1 of 1 people found this helpful
            • 3. Re: Rich Calender isDayEnabled works only once
              mrras

              Thanks for your answer.

              Indeed using a server request for a client operation is not the best solution, but it is the only one I have so far, so I tried it and it works!

              well. almost.

              I implemented the rerender by adding a4j support tag:

               

              {code}

              <rich:calendar id="startDate" value="#{selectorsMB.startDate}" showWeeksBar="false"

                             isDayEnabled="dayEnabledStart" dayStyleClass="disabledClassStart"

                             cellWidth="24px" cellHeight="22px" style="width:80px" showFooter="false">

                   <a4j:support event="onchanged" reRender="endDateWrap"

                                onsubmit="resetRangeSelector();switchNeedToResend(true);"/>

              </rich:calendar>

              {code}

               

               

              The issue I'm facing now is with a predefined date selector I have next to the date boxes.it has several values like "last 28 days", "last month", "last week", etc... and changing it fires a js function that alters the dates like this (after calculating fromDate and toDate):

               

              {code}

              Richfaces.getComponent('calendar',document.getElementById("selectors:selectorsform:startDate"))

                   .selectDate(fromDate);

              Richfaces.getComponent('calendar',document.getElementById("selectors:selectorsform:endDate"))

                   .selectDate(toDate);

              {code}

               

              the result is that startDate changes but endDate doesn't. it flickers to the wanted date but then returns the the previously selected date.

               

              What I believe happens is that after the first selectDate happens (on startDate) the reRender for endDate starts, and it ends after the selectDate for this calender has already executed, so the value changes back to the previous value.

               

              So, is there a way to fire an event to trigger the isDayEnabled and dayStyleClass functions from the client? that will probably solve my problem.

              if not, how do you think I should progress with this issue? I tried adding oncomplete event to one of the calendars a4j support but it ended with just more flickering and incosistant behaviour.

               

              Thanks in advance!


               

              • 4. Re: Rich Calender isDayEnabled works only once
                mrras

                Any ideas about this?

                 

                Thanks in advance.

                • 5. Rich Calender isDayEnabled works only once
                  mrras

                  Did you find any hook to trigger the markup from the client? this is becoming a real issue for me now.

                   

                  Thanks again.

                  • 6. Re: Rich Calender isDayEnabled works only once
                    garytxo

                    Hi there

                    we have something similar in our project, we refresh the departure date calendar by re-rendering on the "onchanged" event on the start date calendar.

                     

                    <rich:calendar id="arrivalDate" value="#{bean.arrivalDate}" isDayEnabled="disableArrivalDays" 
                                             onchanged="#{rich:component('depatureDate')}.render();"/>
                    
                    

                     

                     

                    Hope this is  useful?